Copyright Tarena Corporation,200 9 .All rights reserved
Module 7- 集合和泛型
一、选择题:
Question 1
Given:
11. public class Person {
12. private name;
13. public Person(String name) {
14. this.name = name;
15. }
16. public int hashCode() {
17. return 420;
18. }
19. }
Which is true?
A. The time to find the value from HashMap with a Person key depends
on the size of the map.
B.
Deleting a Person key from a HashMap will delete all map entries for
all keys of type Person.
C.
Inserting a second Person object into a HashSet will cause the first
Person object to be removed as a duplicate.
D. The time to determine whether a Person object is contained in a
HashSet is constant and does NOT depend on the size of the map.
Answer:
A
Question 2
Given:
11.
public static Collection get() {
12. Collection sorted = new LinkedList();
13. sorted.add( " B " ); sorted.add( " C " ); sorted.add( " A " );
14. return sorted;
15. }
16. public static void main(String[] args) {
17. for (Object obj: get()) {
18. System.out.print(obj + " , " );
19. }
20. }
What is the result?
A. A,
B, C,
B. B, C,
A,
C.
Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.
Answer: B