Collections
- Which of these methods can be used to obtain set of all keys in a map?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
keySet() methods is used to get a set containing all the keys used in a map. This method provides set view of the keys in the invoking map.
- Which of these method is used add an element and corresponding key to a map?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Maps revolve around two basic operations – get() and put(). to put a value into a map, use put(), specifying the key and the value. To obtain a value, call get() , passing the key as an argument. The value is returned.
- 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}
- What is the output of this program?
import java.util.*;
public class vector_Example
{
public static void main(String args[])
{
Vector object = new Vector(6,3);
object.addElement(new Integer(5));
object.addElement(new Integer(7));
object.addElement(new Integer(9));
System.out.println(object.elementAt(2));
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
object.elementAt(2) returns the value stored at index 2, which is 9.
- What is the output of this program?
import java.util.*;
public class vector
{
public static void main(String args[])
{
Vector object = new Vector(6,3);
object.addElement(new Integer(9));
object.addElement(new Integer(7));
object.addElement(new Integer(3));
System.out.println(object.capacity());
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
6