1.
Given:
import java.util.*;class Test { public static void main(String[] args) { // insert code here x.add("one"); x.add("two"); x.add("TWO"); System.out.printIn(x.poll()); }}
A. 
List x = new LinkedList();
B. 
TreeSet x = new TreeSet();
C. 
HashSet x = new HashSet();
D. 
Queue x = new PriorityQueue();
E. 
ArrayList x = new ArrayList();
2.
Given:
import java.util.*;class Flubber { public static void main(String[] args) { List x = new ArrayList(); x.add(" x"); x.add("xx"); x.add("Xx"); // insert code here for(String s: x) System.out.println(s);} }
And the output:
xxXx x
Which code, inserted at // insert code here, will produce the preceding output? (Choose all that apply.)
A. 
B. 
Comparable c = Collections.reverse(); Collections.sort(x,c);
C. 
Comparator c = Collections.reverse(); Collections.sort(x,c);
D. 
Comparable c = Collections.reverseOrder(); Collections.sort(x,c);
E. 
Comparator c = Collections.reverseOrder(); Collections.sort(x,c);
3.
Given:
public static void main(String[] args) { // INSERT DECLARATION HERE for (int i = 0; i <= 10; i++) { List row = new ArrayList(); for (int j = 0; j <= 10; j++) row.add(i * j); table.add(row); } for (List row : table) System.out.println(row); }
Which statements could be inserted at // INSERT DECLARATION HERE to allow this code to compile and run? (Choose all that apply.)
A. 
B. 
List table = new ArrayList();
C. 
List table = new ArrayList();
D. 
E. 
4.
Which statements are true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden? (Choose all that apply.)
A. 
If the equals() method returns true, the hashCode() comparison == might return false.
B. 
If the equals() method returns false, the hashCode() comparison == might return true.
C. 
If the hashCode() comparison == returns true, the equals() method must return true.
D. 
If the hashCode() comparison == returns true, the equals() method might return true.
E. 
If the hashCode() comparison ! = returns true, the equals() method might return true.
5.
Given:
10. public static void main(String[] args) {11. Queue q = new LinkedList();12. q.add("Veronica");13. q.add("Wallace");14. q.add("Duncan");15. showAll(q);16. }17.18. public static void showAll(Queue q) {19. q.add(new Integer(42));20. while (!q.isEmpty ( ) )21. System.out.print(q.remove( ) + " ");22. }
What is the result?
A. 
B. 
42 Duncan Wallace Veronica
C. 
D. 
Veronica Wallace Duncan 42
E. 
An exception occurs at runtime.
6.
Given:
public static void before () { Set set = new TreeSet(); set.add("2"); set.add(3); set.add("1"); Iterator it = set.iterator(); while (it.hasNext()) System.out.print(it.next() + " ");}
Which of the following statements are true?
A. 
The before() method will print 1 2
B. 
The before() method will print 1 2 3
C. 
The before() method will print three numbers, but the order cannot be determined.
D. 
The before() method will not: compile.
E. 
The before() method will throw an exception at runtime.
7.
Given:
import java.util.*;class MapEQ { public static void main(String[] args) { Map m = new HashMap(); ToDos tl = new ToDos("Monday"); ToDos t2 = new ToDos("Monday"); ToDos t3 = new ToDos("Tuesday"); m.put(tl, "doLaundry"); m.put(t2, "payBills"); m.put(t3, "cleanAttic"); System.out.printIn(m.size()); }}class ToDos{ String day; ToDos(String d) { day = d; } public boolean equals(Object o) { return ((ToDos)o).day == this.day; } // public int hashCode() ( return 9; }}Which is correct? (Choose all that apply.)
A. 
As the code stands it will not compile.
B. 
As the code stands the output will be 2.
C. 
As the code stands the output will be 3.
D. 
If the hashCode() method is uncommented the output will be 2.
E. 
If the hashCode() method is uncommented the output will be 3.
8.
Given:
12. public class AccountManager {13. private Map accountTotals = new HashMap();14. private int retirementFund;15.16. public int getBalance(String accountName) {17. Integer total = (Integer) accountTotals.get(accountName);18. if (total == null)19. total = Integer.valueOf(0);20. return total.intValue();21. }23. public void setBalance(String accountName, int amount) {24. accountTotals.put(accountName, Integer.valueOf(amount));25. }26. }
This class is to be updated to make use of
appropriate generic types, with no changes in behavior (for better or
worse). Which of these steps could be performed? (Choose three.)
A. 
Replace line 13 with
private Map accountTotals = new HashMap();
B. 
Replace line 13 with
private Map accountTotals = new HashMap();
C. 
Replace lines 17-20 with
Integer total = accountTotals.get(accountName);
if (total == null)
total = 0;
return total;
D. 
Replace line 13 with
private Map accountTotals = new HashMap();
E. 
Replace line 24 with
accountTotals.put(accountName, amount);
9.
Given a properly prepared String array containing five elements, which range of results could a proper invocation of Arrays.binarysearch() produce?
A. 
B. 
C. 
D. 
E. 
10.
Given:
interface Hungry { void munch(E x); }interface Carnivore extends Hungry {}interface Herbivore extends Hungry {}abstract class Plant {}class Grass extends Plant {}abstract class Animal {}class Sheep extends Animal implements Herbivore { public void munch(Sheep x) {}}class Wolf extends Animal implements Carnivore { public void munch(Sheep x) {}}
Which of the following changes (taken separately) would allow this code to compile? (Choose all that apply.)
A. 
Change the Carnivore interface to
interface Carnivore extends Hungry {}
B. 
Change the Sheep class to
class Sheep extends Animal implements Herbivore {
public void munch(Grass x) {}
}
C. 
Change the Sheep class to
class Sheep extends Plant implements Carnivore {
public void munch(Wolf x) {}
}
D. 
Change the Herbivore interface to
interface Herbivore extends Hungry {}
E. 
No changes are necessary.
11.
Which collection class(es) allows you to grow or shrink its size and
provides indexed access to its elements, but whose methods are not
synchronized? (Choose all that apply.)
A. 
B. 
C. 
D. 
E. 
12.
Given:
import java.util.*;public class Group extends HashSet { public static void main(String[] args) { Group g = new Group () ; g.add(new Person("Hans")); g.add(new Person("Lotte")); g.add(new Person("Jane")); g.add(new Person("Hans")); g.add(new Person("Jane")); System.out. printIn ("Total: " + g.size() ); } public boolean add(Object o) { System.out.println("Adding: " + o) ; return super,add(o); }}class Person { private final String name; public Person(String name) { this.name = name; } public String toString() { return name; }}
Which of the following occur at least once when the code is compiled and run? (Choose all that apply.)
A. 
B. 
C. 
D. 
The code does not compile.
E. 
An exception is thrown at runtime.
13.
Given:
import java.util.*;class AlgaeDiesel { public static void main(String [] args) { String [] sa = ("foo", "bar", "baz" }; // insert method invocations here }}
What java.util.Arrays and/or java.util.Collections methods could you use to convert sa to a List and then search the List to find the index of the element whose value is "foo" ? (Choose from one to three methods.)
A. 
B. 
C. 
D. 
E. 
14.
Given that String implements java.lang.CharSequcnce, and:
import java.util.* ;public class LongWordFinder { public static void main(String [] args) { String[] array = { "123", "12345678", "1", "12", "1234567890"}; List list = Arrays.asList(array); Collection resultList = getLongWords(list); } // INSERT DECLARATION HERE { Collection longWords = new ArrayList(); for (E word : coll) if (word.length() > 6) longWords.add(word); return longWords; }}
Which declarations could be inserted at // INSERT DECLARATION HERE so that the program will compile and run? (Choose all that apply.)
A. 
B. 
Public static List getLongWords(Collection coll)
C. 
Public static Collection getLongWords(Collection coll)
D. 
Public static List getLongWords(Collection coll)
E. 
Static public Collection getLongWords(Collection coll)
15.
Given:
12. TreeSet map = new TreeSet();13. map.add("one");14. map.add("two");15. map.add("three");16. map.add("four"};17. map.add("one");18. Iterator it = map.iterator();19. while (it.hasNext() ) {20. System.out.print( it.next() + " " );21. }
What is the result?
A. 
B. 
C. 
D. 
An exception is thrown at runtime.
E. 
The print order is not guaranteed.
16.
Given a method declared as:
public static List process(List nums)
A programmer wants to use this method like this:
// INSERT DECLARATIONS HEREoutput = process(input);
Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)
A. 
ArrayList input = null;
ArrayList output = null;
B. 
ArrayList input = null;
List output = null;
C. 
ArrayList input = null;
List output = null;
D. 
List input = null;
List output = null;
E. 
List input = null;
List output = null;