Answer: generic TreeSet : Questions « Utility Classes « SCJP






Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at java.lang.Integer.compareTo(Integer.java:35)
	at java.util.TreeMap.put(TreeMap.java:545)
	at java.util.TreeSet.add(TreeSet.java:238)
	at MainClass.main(MainClass.java:10)
You can't put both Strings and int s into the same TreeSet.








8.32.Questions
8.32.1.The Object class is final(True/False).
8.32.2.Answer: Object class and final
8.32.3.The Class class can be used to load other classes(True/False).
8.32.4.Answer: class loader
8.32.5.The ClassLoader class can be used to load other classes(True/False).
8.32.6.Answer: ClassLoader and class loading
8.32.7.Which of the following classes is used to perform basic console I/O?
8.32.8.Answer: console I/O
8.32.9.Which of the following is not a wrapper class?
8.32.10.Answer: wrapper class
8.32.11.What is the output from the following code(Boolean class and if statement)?
8.32.12.Answer: Boolean class and if statement
8.32.13.What is the output of the following program(string concatenation)?
8.32.14.Answer: string concatenation
8.32.15.Which of the following methods are methods of the Math class?
8.32.16.Answer: Math class
8.32.17.Error and Exception classes extend Throwable(True/False).
8.32.18.Answer: Error and Exception
8.32.19.The Integer class extends the Number class(True/False).
8.32.20.Answer: Integer class and Number class
8.32.21.What is the output from the following code(Vector class)?
8.32.22.Answer: Vector class
8.32.23.What is the output from the following code(Stack)?
8.32.24.Answer: Stack
8.32.25.Which of the following extend the Collection interface?
8.32.26.Answer: Collection interface
8.32.27.Which of the following may have duplicate elements?
8.32.28.Answer: collection allowing duplicate elements
8.32.29.Can a null value be added to a List?
8.32.30.Answer: null value and List
8.32.31.What is the output of the following program(HashSet)?
8.32.32.Answer: HashSet
8.32.33.What is the output of the following program(TreeMap)?
8.32.34.Answer: TreeMap
8.32.35.Which statements could be inserted at // INSERT DECLARATION HERE to allow this code to compile and run?
8.32.36.Answer: generic List
8.32.37.What is the output(generic TreeSet)?
8.32.38.Answer: generic TreeSet
8.32.39.What is the output(Generic Map)?
8.32.40.Answer: Generic Map