A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

TreeSet in Collection in Java

The set is an Interface, so  we can't make an object. You need to import TreeSet or SortedSet class and thus follow the steps.


import java.util.Set;
import java.util.TreeSet;
public class setExample {
     public static void main(String args[])
    {
        Set s=new TreeSet();
        s.add(10);
        s.add(10);
        s.add(20);
       
        System.out.println(s);
    }
}


output:



Set does not contains any duplicates value. 

LEARN TUTORIALS

.

.