Add elements in TreeSet

We can use add() and addAll() method of TreeSet to add elements to TreeSet boolean add(Object obj) It adds the element obj to the TreeSet. Example import java.util.*; public class TreeSetAddExample { public static void main(String args[]) {   TreeSet<String> ts = new TreeSet<String>();   ts.add(“java”); ts.add(“c”); ts.add(“c++”); System.out.println(ts); } } import java.util.*; public class […]

Share this article on

Treeset overview

TreeSet is a java class which implements Set interface Main features of TreeSet It contains only unique elements, does not allow duplicates. It stores elements in the sorted order It does not maintain the insertion order, elements will be in sorted order. It does not allow null value We can create TreeSet using constructor as […]

Share this article on
< Previous Next >