Fill in the code in Comparable________ c = new Date(); Which of the following me
ID: 3917163 • Letter: F
Question
Fill in the code in Comparable________ c = new Date();
Which of the following methods are in the Collection interface?
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<String> list1 = new ArrayList();
list1.add("Atlanta");
list1.add("Macon");
list1.add("Savanna");
List<String> list2 = new ArrayList();
list2.add("Atlanta");
list2.add("Macon");
list2.add("Savanna");
List<String> 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?
Suppose set1 is ["Atlanta", "Macon"] and set2 is ["Atlanta", "Macon", "Savannah"], which of the following returns true?
Analyze the following code.
import java.util.*;
public class Test {
public static void main(String[] args) throws Exception {
Set<String> set = new TreeSet<String>();
set.add("Red");
set.add("Green");
set.add("Blue");
System.out.println(set.first());
}
}
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<A> set = new HashSet<A>();
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<String> set1 = new LinkedHashSet<String>();
set1.add("New York");
LinkedHashSet<String> set2 = (LinkedHashSet<String>)(set1.clone());
set1.add("Atlanta");
set2.add("Dallas");
System.out.println(set2);
Explanation / Answer
Fill in the code in Comparable________ c = new Date();
Answer:<Date>
Which of the following methods are in the Collection interface?
Answer:
remove(o: E): boolean
removeAll(c: Collection?>): boolean
You can sort an array using the sort method in the Arrays class.
Answer: true
java.util.Vector is a subtype of
Answer: java.util.List
What is the output of the following code?
Answer: true false
Which method do you use to test if an element is in a set or list named x?
Answer:x.contains(element)
Suppose set1 is ["Atlanta", "Macon"] and set2 is ["Atlanta", "Macon", "Savannah"], which of the following returns true?
Answer: set2.contains("Savannah")
Analyze the following code.
Answer:
The program cannot compile, because the first() method is not defined in Set.
If two objects o1 and o2 are equal, what are the values for o1.equals(o2) and o1.hashCode() == o2.hashCode()?
Answer: true true
What is the output for the following code?
Answer: [1, 1, 1, 1]
The printout of the following code is ________.
Answer: [New York, Dallas]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.