Collections
- Which of these class object can be used to form a dynamic array?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Vectors are dynamic arrays, it contains many legacy methods that are not part of collection framework, and hence these methods are not present in ArrayList. But both are used to form dynamic arrays.
- What is the output of this program?
import java.util.*;
public class Map_Exmple
{
public static void main(String args[])
{
TreeMap object = new TreeMap();
object.put("I", new Integer(9));
object.put("L", new Integer(12));
object.put("U", new Integer(21));
System.out.println(object.entrySet());
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
object.entrySet() method is used to obtain a set that contains the entries in the map. This method provides set view of the invoking map.
- What is the output of this program?
import java.util.*;
public class Map_Example
{
public static void main(String args[])
{
HashMap object = new HashMap();
object.put("I", new Integer(9));
object.put("L", new Integer(12));
object.put("U", new Integer(21));
System.out.println(object.get("L"));
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
object.get(“L”) method is used to obtain the value associated with key “L”, which is 12.
- What is the output of this program?
import java.util.*;
public class Map_Example
{
public static void main(String args[])
{
HashMap object = new HashMap();
object.put("D", new Integer(4));
object.put("E", new Integer(5));
object.put("F", new Integer(6));
System.out.println(object.keySet());
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
keySet() method returns a set containing all the keys used in the invoking map. Here keys are characters D, E & F. 4, 5, 6 are the values given to these keys.
- What is the output of this program?
import java.util.*;
public class Map_Example
{
public static void main(String args[])
{
HashMap object = new HashMap();
object.put("D", new Integer(4));
object.put("E", new Integer(5));
object.put("F", new Integer(6));
System.out.println(object);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
{D=4, E=5, F=6}