Search your topic in Java2share
Home > SCJP > QuestionBank
eXTReMe Tracker


12. Collections and Generics (SCJP)

Q: 01 Given:
34. HashMap props = new HashMap();
35. props.put("key45", "some value");
36. props.put("key12", "some other value");
37. props.put("key39", "yet another value");
38. Set s = props.keySet();
39. // insert code here
What, inserted at line 39, will sort the keys in the props HashMap?

A. Arrays.sort(s);
B. s = new TreeSet(s);
C. Collections.sort(s);
D. s = new SortedSet(s);

Answer: B

Q: 02 Click the Exhibit button.
Which statement is true about the set variable on line 12?


A. The set variable contains all six elements from the coll collection, and the order is guaranteed to be
preserved.
B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved.
C. The set variable contains all six elements from the coll collection, but the order is NOT guaranteed to be preserved.
D. The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to be preserved.

Answer: D

Q: 03 Given:
23. Object [] myObjects = {
24. new Integer(12),
25. new String("foo"),
26. new Integer(5),
27. new Boolean(true)
28. };
29. Arrays.sort(myObjects);
30. for(int i=0; i<myObjects.length; i++) {
31. System.out.print(myObjects[i].toString());
32. System.out.print(" ");
33. }
What is the result?
A. Compilation fails due to an error in line 23.
B. Compilation fails due to an error in line 29.
C. A ClassCastException occurs in line 29.
D. A ClassCastException occurs in line 31.
E. The value of all four objects prints in natural order.

Answer: C

Q: 04 Click the Task button.

Solution:

1.Gen<T>
2.T     
3.Gen  
 4.T 
 5.T

13. Inner Classes