Given:
import java.util.TreeSet; class MyClass {//from ww w. j a v a 2 s.c om int size; MyClass(int s) { size = s; } } public class Main { public static void main(String[] args) { TreeSet<Integer> i = new TreeSet<Integer>(); TreeSet<MyClass> d = new TreeSet<MyClass>(); d.add(new MyClass(1)); d.add(new MyClass(2)); d.add(new MyClass(1)); i.add(1); i.add(2); i.add(1); System.out.println(d.size() + " " + i.size()); } }
What is the result?
G is correct.
Class MyClass needs to implement Comparable in order for a TreeSet to be able to contain MyClass objects.