Fill in the code in Comparable________ c = new Date();
Which of the following methods are in the Collection interface?
| deleteAll(c: Collection?>): boolean |
| removeAll(c: Collection?>): boolean |
You can sort an array using the sort method in the Arrays class.
java.util.Vector is a subtype of ________.
What is the output of the following code? import java.util.*; public class Test { public static void main(String[] args) { List list1 = new ArrayList(); list1.add("Atlanta"); list1.add("Macon"); list1.add("Savanna"); List list2 = new ArrayList(); list2.add("Atlanta"); list2.add("Macon"); list2.add("Savanna"); List list3 = new ArrayList(); list3.add("Macon"); list3.add("Savanna"); list3.add("Atlanta"); System.out.println(list1.equals(list2) + " " + list1.equals(list3)); } }
Which method do you use to test if an element is in a set or list named x?
| (element instanceof List) || (element instanceof Set) |
Suppose set1 is ["Atlanta", "Macon"] and set2 is ["Atlanta", "Macon", "Savannah"], which of the following returns true?
| set1.contains("Savannah") |
| set2.contains("Savannah") |
Analyze the following code. import java.util.*; public class Test { public static void main(String[] args) throws Exception { Set set = new TreeSet(); set.add("Red"); set.add("Green"); set.add("Blue"); System.out.println(set.first()); } }
| The program cannot compile, because the first() method is not defined in Set. |
| The program may display Red, Blue, or Green. |
| The program displays Green |
| The program displays Blue |
If two objects o1 and o2 are equal, what are the values for o1.equals(o2) and o1.hashCode() == o2.hashCode()?
What is the output for the following code? import java.util.*; public class Test { public static void main(String[] args) { Set set = new HashSet(); set.add(new A()); set.add(new A()); set.add(new A()); set.add(new A()); System.out.println(set); } } class A { int r = 1; public String toString() { return r + ""; } public boolean equals(Object o) { return this.r == ((A)o).r; } }
The printout of the following code is ________. LinkedHashSet set1 = new LinkedHashSet(); set1.add("New York"); LinkedHashSet set2 = (LinkedHashSet)(set1.clone()); set1.add("Atlanta"); set2.add("Dallas"); System.out.println(set2);
| [New York, Atlanta, Dallas] |