Page: 5
12. Collections and Generics
Q: 19 Click the Task button. 
Solution: public class NumberNames{ private HashMap< String , Integer> map= new HashMap< String , Integer >( ); public void put(String name . int Value) { map.put(name , Value); } public Set<String> getNames( ) { return map.keySet( ); } } Q: 20 Which two statements are true about the hashCode method? (Choose two.) A. The hashCode method for a given class can be used to test for object equality and object inequality for that class. B. The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set. C. The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class. D. The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution. E. The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval. Answer: C, E Q: 21 Click the Task button.  Solution: 1.implements 2.comparable 3.public 4.coompareTo(Object o) 5. i Q: 22 A programmer has an algorithm that requires a java.util.List that provides an efficient implementation of add(0, object), but does NOT need to support quick random access. What supports these requirements? A. java.util.Queue B. java.util.ArrayList C. java.util.LinearList D. java.util.LinkedList Answer: D Q: 23 Click the Task button. 
Solution: ( 1)-------( 3) ( 2)---------(1) (3)-------(4) (4)---------(2)
Page: 5
1
2
3
4
5
6
7
8
9
10
11
12
|