Collections Framework In Java - Study Mode
[#151] How to externally synchronize hashmap?
Correct Answer
(C) Collections.synchronizedMap(new HashMap<String, String>())
[#152] What will be the output of the following Java program? import java.util.*
class Arraylist
{
public static void main(String args[])
{
ArrayList obj = new ArrayList()
obj.add("A")
obj.add("B")
obj.add("C")
obj.add(1, "D")
System.out.println(obj)
}
}
Correct Answer
(B) [A, D, B, C]
[#153] What will be the output of the following Java program? import java.util.*
class Maps
{
public static void main(String args[])
{
TreeMap obj = new TreeMap()
obj.put("A", new Integer(1))
obj.put("B", new Integer(2))
obj.put("C", new Integer(3))
System.out.println(obj.entrySet())
}
}
Correct Answer
(D) [A=1, B=2, C=3]
[#154] What will be the output of the following Java code? import java.util.*
class hashtable
{
public static void main(String args[])
{
Hashtable obj = new Hashtable()
obj.put("A", new Integer(3))
obj.put("B", new Integer(2))
obj.put("C", new Integer(8))
System.out.print(obj.toString())
}
}
Correct Answer
(C) {A=3, C=8, B=2}
[#155] What will be the output of the following Java program? import java.util.*
class Array
{
public static void main(String args[])
{
int array[] = new int [5]
for (int i = 5
i > 0
i--)
array[5 - i] = i
Arrays.sort(array)
System.out.print(Arrays.binarySearch(array, 4))
}
}
Correct Answer
(B) 3