In Java, here it is used in context to add a specific element into a Set collection. The function adds the element only if the specified element is not already present in the set else the function returns False if the element is already present in the Set.
OutputInitial String Array(Containing Duplicates) : [Hello, hi, Wow, cute, thanks, hi, Aww, cute, baby, beloved, Aww]Duplicate Data entered : hi
Duplicate Data entered : cute
Duplicate Data entered : Aww
TreeSet(After Removing Duplicates) : [Aww, Hello, Wow, baby, beloved, cute, hi, thanks]
Final String Array is : [Aww, Hello, Wow, baby, beloved, cute, hi, thanks, null, null, null]