- SortedSet IS-A Set. (1 correct answer)
- true
- false
- SortedSet belongs to the java.util package. (1 correct answer)
- true
- false
- How many of the following methods of SortedSet may throw an exception at runtime? (1 correct answer)
⇒ first()
⇒ last()
⇒ headSet()
⇒ tailSet()
⇒ subSet()
⇒ comparator()
- None.
- Two.
- Three.
- Five.
- What’s the signature of the method headSet()? (1 correct answer)
- SortedSet<E> headSet(E)
- SortedSet<E> headSet(E, E)
- SortedSet<E> headSet(E, boolean)
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedSet<Integer> set = new TreeSet<Integer>();
set.last();
}
- A NoSuchElementException is thrown.
- It compiles and runs fine.
- Compilation fails.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedSet<Integer> set = new TreeSet<Integer>();
set.add(7);
set.add(-12);
SortedSet<Integer> sub = set.subSet(-100, 100);
System.out.format("%d %d", set.size(), sub.size());
}
- It prints “2 2″.
- It prints “2 0″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedSet<Integer> set = new TreeSet<Integer>();
set.add(7);
set.add(-12);
SortedSet<Integer> sub = set.subSet(-100, 100);
sub.add(9);
System.out.format("%d %d", set.size(), sub.size());
}
- An IllegalArgumentException is thrown.
- It prints “2 3″.
- It prints “2 1″.
- It prints “3 3″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedSet<Integer> set = new TreeSet<Integer>();
set.add(7);
set.add(-12);
SortedSet<Integer> sub = set.subSet(-100, 100);
sub.add(-100);
System.out.format("%d %d", set.size(), sub.size());
}
- An IllegalArgumentException is thrown.
- It prints “2 3″.
- It prints “2 1″.
- It prints “3 3″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedSet<Integer> set = new TreeSet<Integer>();
set.add(7);
set.add(-12);
SortedSet<Integer> sub = set.subSet(-100, 100);
sub.add(100);
System.out.format("%d %d", set.size(), sub.size());
}
- An IllegalArgumentException is thrown.
- It prints “2 3″.
- It prints “2 1″.
- It prints “3 3″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedSet<Integer> set = new TreeSet<Integer>();
set.add(7);
set.add(-12);
SortedSet<Integer> sub = set.subSet(-100, 100);
sub.add(99);
System.out.format("%d %d", set.size(), sub.size());
}
- An IllegalArgumentException is thrown.
- It prints “2 3″.
- It prints “2 1″.
- It prints “3 3″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedSet<Integer> set = new TreeSet<Integer>();
set.add(7);
set.add(-12);
SortedSet<Integer> sub = set.subSet(-100, 100);
sub.add(7);
System.out.format("%d %d", set.size(), sub.size());
}
- An IllegalArgumentException is thrown.
- It prints “2 1″.
- It prints “2 2″.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
SortedSet set = new TreeSet();
set.add(7);
set.add(-12);
SortedSet sub = set.subSet("Hello!", 100);
System.out.format("%d %d", set.size(), sub.size());
}
- An IllegalArgumentException is thrown at runtime.
- A ClassCastException is thrown at runtime.
- Compilation fails.
- It prints “2 0″.
- It prints “2 2″.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
SortedSet<Integer> set = new TreeSet<Integer>();
set.add("Hello!");
}
- A ClassCastException is thrown at runtime.
- Compilation fails.
- None of the above.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
SortedSet set = new TreeSet();
set.add("Hello!");
}
- A ClassCastException is thrown at runtime.
- Compilation fails.
- None of the above.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
SortedSet set = new TreeSet();
set.add("Hello!");
set.add(1);
}
- A ClassCastException is thrown at runtime.
- Compilation fails.
- None of the above.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
SortedSet set = new TreeSet();
set.add(null);
set.add(1);
}
- An NullPointerException is thrown at runtime.
- A ClassCastException is thrown at runtime.
- Compilation fails.
- None of the above.
- NavigableSet extends SortedSet. (1 correct answer)
- true
- false
- How many of the following methods of NavigableSet may throw an exception at runtime? (1 correct answer)
⇒ lower()
⇒ higher()
⇒ floor()
⇒ ceiling()
⇒ pollFirst()
⇒ pollLast()
- None.
- Two.
- Four.
- All.
- What’s the signature of the method lower()? (1 correct answer)
- E lower(E)
- boolean lower(E)
- E lower(NavigableSet<E>)
- In the NavigableSet interface there are 2 overloaded methods with the name subSet. (1 correct answer)
- true
- false
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.add(-12);
set.add(24);
System.out.format("%d %d %d %d",
set.lower(-12),
set.lower(0),
set.lower(24),
set.lower(100)
);
}
- An exception is thrown at runtime.
- It prints “null -12 -12 24″.
- It prints “-12 -12 24 24″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.add(-12);
set.add(24);
System.out.format("%d %d %d %d",
set.floor(-12),
set.floor(0),
set.floor(24),
set.floor(100)
);
}
- An exception is thrown at runtime.
- It prints “null -12 -12 24″.
- It prints “-12 -12 24 24″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.add(-12);
set.add(24);
System.out.format("%d %d %d %d",
set.higher(-12),
set.higher(0),
set.higher(24),
set.higher(100)
);
}
- An exception is thrown at runtime.
- It prints “24 24 null null”.
- It prints “-12 24 24 null”.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.add(-12);
set.add(24);
System.out.format("%d %d %d %d",
set.ceiling(-12),
set.ceiling(0),
set.ceiling(24),
set.ceiling(100)
);
}
- An exception is thrown at runtime.
- It prints “24 24 null null”.
- It prints “-12 24 24 null”.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.add(-12);
set.add(24);
set.add(-28);
set.add(-0);
set.add(0);
set.add(+0);
set.add(11);
set.add(145);
System.out.format("%d %d %d %d",
set.higher(-28),
set.lower(24),
set.floor(-0),
set.ceiling(100)
);
}
- An exception is thrown at runtime.
- It prints “-12 11 0 100″.
- It prints “-12 11 0 145″.
- It prints “-28 24 0 100″.
- It prints “-28 24 0 145″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.pollFirst();
System.out.println(set.size());
}
- An exception is thrown at runtime.
- Compilation fails.
- It prints “0″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.first();
System.out.println(set.size());
}
- An exception is thrown at runtime.
- Compilation fails.
- It prints “0″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.add(1);
set.add(2);
set.add(4);
NavigableSet<Integer> sub = set.headSet(4);
System.out.println(sub.last());
}
- An exception is thrown at runtime.
- Compilation fails.
- It prints “4″.
- It prints “2″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.add(1);
set.add(2);
set.add(4);
NavigableSet<Integer> sub = set.headSet(4, true);
System.out.println(sub.last());
}
- An exception is thrown at runtime.
- Compilation fails.
- It prints “4″.
- It prints “2″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableSet<Integer> set = new TreeSet<Integer>();
set.add(1);
set.add(2);
set.add(4);
for (Iterator iterator = set.descendingSet().iterator();
iterator.hasNext();) {
System.out.format("%d ", iterator.next());
}
}
- It prints “1 2 4 “.
- It prints “4 2 1 “.
- Compilation fails.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void add(Set<? super String> set) {
set.add(null);
System.out.println(set.size());
}
public static void main(String[] args) {
Set<String> set = new HashSet<String>();
add(set);
}
}
- It prints “0″.
- It prints “1″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void add(Set<? super String> set) {
set.add(null);
set.add(null);
System.out.println(set.size());
}
public static void main(String[] args) {
Set<String> set = new HashSet<String>();
add(set);
}
}
- It prints “0″.
- It prints “1″.
- It prints “2″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void add(Set<? super String> set) {
set.add("Hi");
set.add("Hi");
System.out.println(set.size());
}
public static void main(String[] args) {
Set<String> set = new HashSet<String>();
add(set);
}
}
- It prints “0″.
- It prints “1″.
- It prints “2″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void add(Set set) {
set.add("Hi");
set.add(1);
System.out.println(set.size());
}
public static void main(String[] args) {
Set<String> set = new HashSet<String>();
add(set);
}
}
- It prints “0″.
- It prints “1″.
- It prints “2″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void add(Set<? super String> set) {
set.add(null);
System.out.println(set.size());
}
public static void main(String[] args) {
Set<String> set = new TreeSet<String>();
add(set);
}
}
- It prints “0″.
- It prints “1″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void add(Set<? super String> set) {
set.add(null);
set.add(null);
System.out.println(set.size());
}
public static void main(String[] args) {
Set<String> set = new TreeSet<String>();
add(set);
}
}
- It prints “0″.
- It prints “1″.
- It prints “2″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void add(Set<? super String> set) {
set.add("Hi");
set.add("Hi");
System.out.println(set.size());
}
public static void main(String[] args) {
Set<String> set = new TreeSet<String>();
add(set);
}
}
- It prints “0″.
- It prints “1″.
- It prints “2″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void add(Set set) {
set.add("Hi");
set.add(1);
System.out.println(set.size());
}
public static void main(String[] args) {
Set<String> set = new TreeSet<String>();
add(set);
}
}
- It prints “0″.
- It prints “1″.
- It prints “2″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void print(Set<? extends String> set) {
for (String element : set) {
System.out.format("%s ", element);
}
}
public static void main(String[] args) {
Set<String> set = new LinkedHashSet<String>();
set.add("A");
set.add("J");
set.add("A");
set.add("X");
print(set);
}
}
- It prints “A J A X “.
- It prints “A J X “.
- The output cannot be determined.
- What is the output of this code? (1 correct answer)
import java.util.*;
public class TestSet {
static void print(Set<? extends String> set) {
for (String element : set) {
System.out.format("%s ", element);
}
}
public static void main(String[] args) {
Set<String> set = new HashSet<String>();
set.add("A");
set.add("J");
set.add("A");
set.add("X");
print(set);
}
}
- It prints “A J A X “.
- It prints “A J X “.
- The output cannot be determined.
- SortedMap IS-A Collection. (1 correct answer)
- true
- false
- SortedMap IS-A Map. (1 correct answer)
- true
- false
- All the following methods are defined in SortedMap. (1 correct answer)
⇒ firstKey()
⇒ lastKey()
⇒ headMap()
⇒ tailMap()
⇒ subMap()
⇒ comparator()
- true
- false
- How many of the following methods of SortedMap may throw an exception at runtime? (1 correct answer)
⇒ firstKey()
⇒ lastKey()
⇒ headMap()
⇒ tailMap()
⇒ subMap()
⇒ comparator()
- None.
- Two.
- Three.
- Five.
- Consider SortedMap<K,V>. What’s the signature of the method firstKey()? (1 correct answer)
- K firstKey()
- V firstKey()
- K firstKey(K)
- V firstKey(K)
- Consider SortedMap<K,V>. What’s the signature of the method tailMap()? (1 correct answer)
- SortedMap<K,V> tailMap(K)
- SortedMap<K,V> tailMap(K, V)
- SortedMap<K,V> tailMap(K, boolean)
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.last();
}
- A NoSuchElementException is thrown.
- It compiles and runs fine.
- Compilation fails.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.lastKey();
}
- A NoSuchElementException is thrown.
- It compiles and runs fine.
- Compilation fails.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.lastEntry();
}
- A NoSuchElementException is thrown.
- It compiles and runs fine.
- Compilation fails.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.put("B", 1);
System.out.println(map.put("B", 2));
}
- It prints “B”.
- It prints “null”.
- It prints “1″.
- It prints “2″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.put("B", 1);
map.put("B", 2);
map.put("a", 4);
System.out.format("%s %d",
map.lastKey(),
map.size());
}
- It prints “a 2″.
- It prints “a 3″.
- It prints “B 2″.
- It prints “B 3″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.put("K", 1);
map.put("B", 2);
map.put("F", 3);
System.out.println(map.tailMap("C").size());
}
- It prints “0″.
- It prints “1″.
- It prints “2″.
- It prints “3″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.put("K", 1);
map.put("B", 2);
map.put("F", 3);
System.out.println(map.tailMap("C").put("D", 1));
}
- An IllegalArgumentException is thrown.
- It prints “null”.
- It prints “D”.
- It prints “F”.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.put("K", 1);
map.put("B", 2);
map.put("F", 3);
System.out.println(map.tailMap("c").size());
}
- An IllegalArgumentException is thrown.
- It prints “0″.
- It prints “1″.
- It prints “2″.
- It prints “3″.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.put("K", 1);
map.put("B", 2);
map.put("F", 3);
System.out.println(map.tailMap("c").put("c", 1));
}
- An IllegalArgumentException is thrown.
- It prints “null”.
- It prints “c”.
- It prints “F”.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
map.put("K", 1);
map.put("B", 2);
map.put("F", 3);
System.out.println(map.tailMap("c").put("A", 1));
}
- An IllegalArgumentException is thrown.
- It prints “null”.
- It prints “c”.
- It prints “F”.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
Map map = new TreeMap();
map.put("K", 1);
map.put("L", "L");
}
- An exception is thrown at runtime.
- Compilation fails.
- None of the above.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
Map map = new TreeMap();
map.put("K", 1);
map.put(2, "L");
}
- An exception is thrown at runtime.
- Compilation fails.
- None of the above.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
Map map = new LinkedHashMap();
map.put("K", 1);
map.put(2, "L");
}
- An exception is thrown at runtime.
- Compilation fails.
- None of the above.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
Map map = new LinkedHashMap();
map.put("K", 1);
map.put(2, "L");
for (Object element : map.keySet()) {
System.out.print(element);
}
}
- An exception is thrown at runtime.
- Compilation fails.
- None of the above.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
new LinkedHashMap<String, Integer>().put(null, null);
new HashMap<Object, Number>().put(null, null);
new TreeMap<String, Queue<String>>().put(null, null);
}
- An exception is thrown at runtime.
- It compiles and runs fine.
- Compilation fails.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
new Hashtable().put(1, null);
}
- An exception is thrown at runtime.
- It compiles and runs fine.
- Compilation fails.
- What happens when this code gets executed? (1 correct answer)
public static void main(String[] args) {
new Hashtable().put(null, 1);
}
- An exception is thrown at runtime.
- It compiles and runs fine.
- Compilation fails.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
Map<String, Integer> map = new LinkedHashMap<String, Integer>();
map.put("J", 1);
map.put("A", 2);
map.put("V", 3);
map.put("A", 4);
for (Object element : map.keySet()) {
System.out.format("%s ", element);
}
}
- It prints “J A V A”
- It prints “J A V”
- It prints “A J V”
- The output order cannot be guaranteed.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
Map<String, Integer> map = new TreeMap<String, Integer>();
map.put("J", 1);
map.put("A", 2);
map.put("V", 3);
map.put("A", 4);
for (Object element : map.keySet()) {
System.out.format("%s ", element);
}
}
- It prints “J A V A”
- It prints “J A V”
- It prints “A J V”
- The output order cannot be guaranteed.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("T", 1);
map.put("M", 2);
map.keySet().add("A");
System.out.println(map.size());
}
- It prints “2″
- It prints “3″
- An exception is thrown at runtime.
- What happens when this code gets compiled and executed? (1 correct answer)
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("T", 1);
map.put("M", 2);
map.keySet().remove("T");
System.out.println(map.size());
}
- It prints “1″
- It prints “2″
- An exception is thrown at runtime.
- All the following methods belong to NavigableMap. (1 correct answer)
⇒ lowerEntry()
⇒ higherEntry()
⇒ floorEntry()
⇒ ceilingEntry()
- true
- false
- All the following methods belong to NavigableMap. (1 correct answer)
⇒ pollFirstEntry()
⇒ pollLastEntry()
⇒ firstEntry()
⇒ lastEntry()
- true
- false
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(5, "D");
map.put(-1, "A");
map.put(7, "O");
System.out.format("%d %d %d %d",
map.lowerKey(-100),
map.lowerKey(5),
map.lowerKey(6),
map.lowerKey(100)
);
}
- It prints “null -1 5 7″.
- It prints “null 5 5 7″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(5, "D");
map.put(-1, "A");
map.put(7, "O");
System.out.format("%d %d %d %d",
map.floorKey(-100),
map.floorKey(5),
map.floorKey(6),
map.floorKey(100)
);
}
- It prints “null -1 5 7″.
- It prints “null 5 5 7″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(5, "D");
map.put(-1, "A");
map.put(7, "O");
System.out.format("%d %d %d %d",
map.higherKey(-100),
map.higherKey(5),
map.higherKey(6),
map.higherKey(100)
);
}
- It prints “-1 7 7 null”.
- It prints “-1 5 7 null”.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(5, "D");
map.put(-1, "A");
map.put(7, "O");
System.out.format("%d %d %d %d",
map.ceilingKey(-100),
map.ceilingKey(5),
map.ceilingKey(6),
map.ceilingKey(100)
);
}
- It prints “-1 7 7 null”.
- It prints “-1 5 7 null”.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(5, "D");
map.put(-1, "A");
map.put(7, "O");
System.out.format("%s %s %s %s",
map.lowerEntry(-100),
map.lowerEntry(5),
map.lowerEntry(6),
map.lowerEntry(100)
);
}
- It prints “null -1=A 5=D 7=O”.
- It prints “null 5=D 5=D 7=O”.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(5, "D");
map.put(-1, "A");
map.put(7, "O");
System.out.format("%s %s %s %s",
map.floorEntry(-100),
map.floorEntry(5),
map.floorEntry(6),
map.floorEntry(100)
);
}
- It prints “null -1=A 5=D 7=O”.
- It prints “null 5=D 5=D 7=O”.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(5, "D");
map.put(-1, "A");
map.put(7, "O");
System.out.format("%s %s %s %s",
map.higherEntry(-100),
map.higherEntry(5),
map.higherEntry(6),
map.higherEntry(100)
);
}
- It prints “-1=A 7=O 7=O null”.
- It prints “-1=A 5=D 7=O null”.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(5, "D");
map.put(-1, "A");
map.put(7, "O");
System.out.format("%s %s %s %s",
map.ceilingEntry(-100),
map.ceilingEntry(5),
map.ceilingEntry(6),
map.ceilingEntry(100)
);
}
- It prints “-1=A 7=O 7=O null”.
- It prints “-1=A 5=D 7=O null”.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(34, "J");
map.put(-1, "a");
map.put(70, "v");
map.put(5, "a");
map.put(-1, "2");
System.out.format("%s %s %s %s",
map.ceilingEntry(-100),
map.floorEntry(5),
map.higherEntry(6),
map.lowerKey(5)
);
}
- It prints “-1=2 5=a 34=J -1″.
- It prints “-1=a 5=a 34=J -1″.
- It prints “-1=2 5=a 34=J 5″.
- It prints “-1=a 5=a 34=J 5″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.lastEntry();
System.out.println(map.size());
}
- An exception is thrown at runtime.
- Compilation fails.
- It prints “0″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.pollFirstEntry();
System.out.println(map.size());
}
- An exception is thrown at runtime.
- Compilation fails.
- It prints “0″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.firstKey();
System.out.println(map.size());
}
- An exception is thrown at runtime.
- Compilation fails.
- It prints “0″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(1, "A");
map.put(2, "B");
map.put(3, "C");
NavigableMap<Integer, String> sub =
map.subMap(0, 3);
System.out.println(sub.lastKey());
}
- It prints “2″.
- It prints “3″.
- Compilation fails.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(1, "A");
map.put(2, "B");
map.put(3, "C");
NavigableMap<Integer, String> sub =
map.subMap(0, false, 3, false);
System.out.println(sub.lastKey());
}
- It prints “2″.
- It prints “3″.
- Compilation fails.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(1, "A");
map.put(2, "B");
map.put(3, "C");
NavigableMap<Integer, String> sub =
map.subMap(0, false, 3, false);
map.put(4, "D");
System.out.format("%d %d", map.size(), sub.size());
}
- It prints “2 2″.
- It prints “3 2″.
- It prints “3 3″.
- It prints “4 2″.
- It prints “4 3″.
- Compilation fails.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
NavigableMap<Integer, String> map =
new TreeMap<Integer, String>();
map.put(1, "A");
map.put(2, "B");
map.put(3, "C");
NavigableMap<Integer, String> sub =
map.subMap(0, false, 3, false);
sub.put(4, "D");
System.out.format("%d %d", map.size(), sub.size());
}
- It prints “2 2″.
- It prints “3 2″.
- It prints “3 3″.
- It prints “4 2″.
- It prints “4 3″.
- Compilation fails.
- An exception is thrown at runtime.
- Queue is an interface. (1 correct answer)
- true
- false
- PriorityQueue IS-A Queue. (1 correct answer)
- true
- false
- PriorityQueue IS-A AbstractQueue. (1 correct answer)
- true
- false
- All the following are methods of Queue. (1 correct answer)
⇒ offer()
⇒ poll()
⇒ peek()
⇒ add()
⇒ remove()
⇒ element()
- true
- false
- How many of the following methods of Queue may throw an exception at runtime? (1 correct answer)
⇒ offer()
⇒ poll()
⇒ peek()
- One.
- Two.
- Three.
- How many of the following methods of Queue may throw an exception at runtime? (1 correct answer)
⇒ add()
⇒ remove()
⇒ element()
- One.
- Two.
- Three.
- Consider Queue<E>. What’s the signature of the method offer()? (1 correct answer)
- E offer(E)
- void offer(E)
- boolean offer(E)
- Consider Queue<E>. What’s the signature of the method peek()? (1 correct answer)
- E peek()
- E peek(E)
- boolean peek(E)
- In the Queue interface there are 2 overloaded methods with the name remove. (1 correct answer)
- true
- false
- In the Queue interface both add() and offer() add an element to the queue. (1 correct answer)
- true
- false
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
System.out.println(queue.add(null));
}
- It prints “true”.
- It prints “false”.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
System.out.println(queue.offer(null));
}
- It prints “true”.
- It prints “false”.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
System.out.println(queue.peek());
}
- It prints “null”.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
System.out.println(queue.poll());
}
- It prints “null”.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
System.out.println(queue.element());
}
- It prints “null”.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
System.out.println(queue.remove());
}
- It prints “null”.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
System.out.format("%b %b %d",
queue.add("A"),
queue.add("A"),
queue.size());
}
- It prints “true true 2″.
- It prints “true false 1″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
queue.add("E");
queue.add("J");
queue.add("B");
queue.add("3");
System.out.println(queue.element());
}
- It prints “B”.
- It prints “J”.
- It prints “3″.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>(
Collections.reverseOrder());
queue.add("E");
queue.add("J");
queue.add("B");
queue.add("3");
System.out.println(queue.element());
}
- It prints “B”.
- It prints “J”.
- It prints “3″.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>(
4, Collections.reverseOrder());
queue.add("E");
queue.add("J");
queue.add("B");
queue.add("3");
System.out.println(queue.element());
}
- It prints “B”.
- It prints “J”.
- It prints “3″.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
queue.add("J");
queue.add("A");
queue.add("V");
queue.add("A");
Arrays.sort(queue.toArray());
for (String element : queue) {
System.out.format("%s ", element);
}
}
- It prints “J A V A”.
- It prints “A A J V”.
- The output order is not guaranteed.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
queue.add("J");
queue.add("A");
queue.add("V");
queue.add("A");
String[] array = queue.toArray(new String[0]);
Arrays.sort(array);
for (String element : array) {
System.out.format("%s ", element);
}
}
- It prints “J A V A”.
- It prints “A A J V”.
- The output order is not guaranteed.
- What happens when this code is executed? (1 correct answer)
public static void main(String[] args) {
Queue queue = new PriorityQueue();
queue.add(null);
}
- An exception is thrown at runtime.
- It runs just fine.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue queue = new PriorityQueue();
queue.add(1);
queue.add("J");
System.out.print(queue.element());
}
- It prints “J”.
- It prints “1″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
Queue<String> queue = new PriorityQueue<String>();
queue.add("Z");
queue.add("T");
queue.add("F");
queue.add("A");
queue.add("A");
queue.add("C");
queue.offer("G");
queue.poll();
queue.peek();
queue.remove();
queue.element();
System.out.format("%s %d",
queue.poll(),
queue.size()
);
}
- It prints “A 6″.
- It prints “A 5″.
- It prints “C 5″.
- It prints “C 4″.
- It prints “F 4″.
- It prints “F 3″.
- List is an interface. (1 correct answer)
- true
- false
- LinkedList IS-A List. Also, LinkedList IS-A Queue since Java 1.5. (1 correct answer)
- true
- false
- In the List interface there are two overloaded methods with the name remove.
- true
- false
- In the List interface there are two overloaded methods with the name addAll.
- true
- false
- Consider List<E>. What is the signature of the method lastIndexOf?
- E lastIndexOf(int)
- int lastIndexOf(E)
- int lastIndexOf(Object)
- Consider List<E>. What is the signature of the method set?
- E set(int, E)
- int set(int, E)
- boolean set(int, E)
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
List<Integer> sub = list.subList(0, 1);
System.out.println(sub.size());
}
- It prints “0″.
- It prints “1″.
- Compilation fails.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
List<Integer> sub = list.subList(0, 0);
System.out.println(sub.size());
}
- It prints “0″.
- It prints “1″.
- Compilation fails.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List list = new ArrayList();
list.add(1);
list.add(2);
for (int element : list) {
System.out.format("%d ", element);
}
}
- It prints “1 2 “.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
for (int element : list) {
System.out.format("%d ", element);
}
}
- It prints “1 2 “.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
for (Object element : list) {
System.out.format("%d ", element);
}
}
- It prints “1 2 “.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List list = new ArrayList();
list.add(1);
list.add(2);
for (Object element : list) {
System.out.format("%d ", element);
}
}
- It prints “1 2 “.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<String> list = new LinkedList<String>();
list.add("X");
list.add("M");
list.add("L");
for (String element : list) {
System.out.format("%s ", element);
}
}
- It prints “X M L “.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<String> list = new LinkedList<String>();
list.add("X");
list.add("M");
list.add("L");
System.out.println(list.peek());
}
- It prints “X”.
- It prints “L”.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<String>();
list.add("X");
list.add("M");
list.add("L");
System.out.println(list.peek());
}
- It prints “X”.
- It prints “L”.
- Compilation fails.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Number> list = new ArrayList<Number>();
list.add(7);
list.add(8);
list.add(9);
list.remove(7);
System.out.println(list.size());
}
- It prints “2″.
- It prints “3″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Number> list = new ArrayList<Number>();
list.add(7);
list.add(8);
list.add(9);
list.remove(Integer.valueOf(7));
System.out.println(list.size());
}
- It prints “2″.
- It prints “3″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Number> list = new ArrayList<Number>();
list.add(7);
list.add(8);
list.add(7);
Number index = list.get(7);
System.out.println(index);
}
- It prints “0″.
- It prints “2″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Number> list = new ArrayList<Number>();
list.add(7);
list.add(8);
list.add(7);
Number index = list.get(Integer.valueOf(7));
System.out.println(index);
}
- It prints “0″.
- It prints “2″.
- An exception is thrown at runtime.
- What is the output of this code? (1 correct answer)
public static void main(String[] args) {
List<Number> list = new ArrayList<Number>();
System.out.format("%b %b %b %d",
list.add(7),
list.add(null),
list.add(7),
list.size());
}
- It prints “true false false 1″.
- It prints “true true false 2″.
- It prints “true false true 2″.
- It prints “true true true 3″.
- An exception is thrown at runtime.