TreeSet_Iterator_Generics1.htm
 
This example is an updated version of : TreeMap_Map_compared.htm, enahnced with Generics , as TreeSet<String> set = new TreeSet<String>();
  • Also View TreeMap_Map_compared.htm to compare the uses of TreeSet/TreeMap

Complete Code:

/**
*
*/
import java.io.*;

import javax.swing.JOptionPane;

import java.net.URI;
import java.util.*;
/**
* @author Manas9
*
*/
public class ClassTemplate1 {
/**
*
*/
public ClassTemplate1() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args)
throws Exception { // TODO Auto-generated method stub]
try {
//
Process p1 = new Process();
p1.method_1();
//
} catch (NumberFormatException exc) {
//Process
}
}
}// end of class template
//
//Processing with ListIterator
class Process
{
//String first[] = {"Java","A+","C#","XML","JSP","PHP","Z", "C#"};
//to be used with set add all change other wise
String[] second = {"0.0","0.1","0.2","0.3","0.2","0.4"};
public Process()
{
System.out.println("Default) constructor");
}
public void method_1()
{
TreeSet<String> set = new TreeSet<String>();
for(String s1 : second)
{ set.add(s1); }
System.out.println(set);
Iterator<String> it = set.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}

Runtime View