Answers for "what does treeset need in java collection"

0

TreeSet in java

// java treeset example
import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetExamples
{
   public static void main(String[] args)
   {
      TreeSet<String> ts = new TreeSet<String>();
      ts.add("red");
      ts.add("blue");
      ts.add("green");
      ts.add("red");
      Iterator<String> iterate = ts.iterator();
      while(iterate.hasNext())
      {
         System.out.println(iterate.next());
      }
   }
}
Posted by: Guest on November-26-2020
0

java treeset

import java.util.*;

// Declare the variable using the interface of the object for flexibility.
// Non-primative data types only.
Set<String> movies = new TreeSet<String>();

movies.add(E);
// TreeSet will be sorted by element.
// Work with any comparable object.

movies.add("The Shining");
movies.add("Dawn of the Dead");
movies.add("Zombieland");
Posted by: Guest on March-16-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language