Java TreeSet add element

Introduction

To add element to TreeSet in Java

treeSet.add(object);

Full source

import java.util.TreeSet; 
 
public class Main { 
  public static void main(String args[]) { 
    // Create a hash set. 
    TreeSet<String> hs = new TreeSet<String>(); 
     //from   ww  w  .  j a  v  a 2 s. c o  m
    // Add elements to the hash set. 
    hs.add("CSS"); 
    hs.add("HTML"); 
    hs.add("Java"); 
    hs.add("Javascript"); 
    hs.add("SQL");
    hs.add("demo2s.com");   

    System.out.println(hs); 
  } 
}



PreviousNext

Related