A
Arthi J
public class Drink implements Comparable {
public String address;
public String name;
public int compareTo(Object o) {
return 1;
}
}
import java.util.*;
public class testClass
{
public static void main(String args[])
{
Drink one = new Drink();
Drink two = new Drink();
one.address = "b";
two.address = "a";
one.name= "Coffee";
two.name= "Tea";
TreeSet set = new TreeSet();
set.add(one);
set.add(two);
Iterator it = set.iterator();
while(it.hasNext())
{
Drink temp = (Drink) it.next();
System.out.println(temp.name);
System.out.println(temp.address);
}
}
}
Output:
public String address;
public String name;
public int compareTo(Object o) {
return 1;
}
}
import java.util.*;
public class testClass
{
public static void main(String args[])
{
Drink one = new Drink();
Drink two = new Drink();
one.address = "b";
two.address = "a";
one.name= "Coffee";
two.name= "Tea";
TreeSet set = new TreeSet();
set.add(one);
set.add(two);
Iterator it = set.iterator();
while(it.hasNext())
{
Drink temp = (Drink) it.next();
System.out.println(temp.name);
System.out.println(temp.address);
}
}
}
Output: