SCJP Collections
By: admin - Tuesday, September 9th, 2008 at 10:55 am
QUESTION : 1
What is the result of attempting to compile and run the following code?
public class Test1{
public static void main(String[] args)
{
Integer int1 = new Integer(10);
Vector vec1 = new Vector();
LinkedList list = new LinkedList();
vec1.add(int1);
list.add(int1);
if(vec1.equals(list)) System.out.println("equal");
else System.out.println("not equal");
}
}
1. The code will fail to compile.
2. Runtime error due to incompatible object comparison
3. Will run and print "equal".
4. Will run and print "not equal".
ANS : 3
correct answer/s : 3
QUESTION : 2
What is the result of attempting to compile and run the following code?
public class Test {
public static void main(String[] args){
Integer a = new Integer(4);
Integer b = new Integer(8);
Integer c = new Integer(4);
HashSet hs = new HashSet();
hs.add(a);
hs.add(b);
hs.add(c);
System.out.println(hs);
}
}
1. Will print [8, 4]
2. Will print [4, 8, 4]
3. Will print [8, 4, 4]
ANS : 1
correct answer/s : 1
QUESTION : 3
What is the result of attempting to compile and run the following code?
public class Test {
public static void main(String[] args){
Integer a = new Integer(4);
Integer b = new Integer(8);
Integer c = new Integer(4);
TreeSet hs = new TreeSet();
ts.add(a);
ts.add(b);
ts.add(c);
System.out.println(ts);
}
}
1. Will print [8, 4]
2. Will print [4, 8, 4]
3. Will print [8, 4, 4]
4. Will print [4, 8]
5. Will print [4, 4, 8]
ANS : 4
correct answer/s : 4
QUESTION : 4
What will this print out ?
public class Test {
public static void main(String[] args){
Integer a = new Integer(8);
Integer b = new Integer(4);
Integer c = new Integer(4);
Vector vec = new Vector();
Iterator itr;
vec.add(a);
vec.add(b);
vec.add(c);
itr = vec.iterator();
while (itr.hasNext()) {
System.out.println("" + itr.next());
}
}
}
1. 8 , 4 and 4
2. 4 , 4 and 8
3. 8 and 4
4. 4 and 8
ANS : 1
correct answer/s : 1
QUESTION : 5
Which of these statements are true?
1. HashTable is a sub class of Dictionary
2. ArrayList is a sub class of Vector
3. LinkedList is a subclass of ArrayList
4. Stack is a subclass of Vector
ANS : 1,4
correct answer/s : 1,4
QUESTION : 6
Which of these statements are true?
1. LinkedList extends List
2. AbstractSet extends Set
3. HashSet extends AbstractSet
4. WeakHashMap extends HashMap
5. TreeSet extends AbstractSet
ANS : 3,5
correct answer/s : 3,5
QUESTION : 7
Which of these statements are true?
1. A HashSet does not permit duplicates
2. A Vector permits duplicates
3. A TreeSet is an ordered Set
4. A LinkedList is sorted in descending order
5. A LinkedList is sorted in ascending order
ANS : 1,2,3
correct answer/s : 1,2,3
QUESTION : 8
True or False.
A WeakHashMap is synchronized.
1. True
2. False
ANS : 2
correct answer/s : 2
QUESTION : 9
True or False.
A Set rejects duplicates and is ordered
1. True
2. False
ANS : 2
correct answer/s : 2
QUESTION : 10
Select the true statements
1. AbstractSet extends AbstractCollection
2. AbstractList extends AbstractCollection
3. HashSet extends AbstractSet
4. Vector extends AbstractList
5. AbstrctSequentialList extends AbstractList
6. LinkedList extends AbstrctSequentialList
ANS : 1,2,3,4,5,6
correct answer/s : 1,2,3,4,5,6