Collections
- Which of these object stores association between keys and values?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Map
- What is the output of this program?
import java.util.*;
public class TreeSet_Example
{
public static void main(String args[])
{
TreeSet object = new TreeSet();
object.add("7");
object.add("0");
object.add("9");
object.add("5");
object.add("6");
System.out.println(object);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
TreeSet class uses set to store the values added by function add in ascending order using tree for storage
- What is the output of this program?
import java.util.*;
public class HashSet_Example
{
public static void main(String args[])
{
HashSet object = new HashSet();
object.add("I");
object.add("L");
object.add("U");
System.out.println(object + " " + object.size());
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
HashSet obj creates an hash object which implements Set interface, object.size() gives the number of elements stored in the object object which in this case is 3.
- What is the output of this program?
import java.util.*;
public class Linkedlist_Example
{
public static void main(String args[])
{
LinkedList object = new LinkedList();
object.add("I");
object.add("L");
object.add("U");
object.removeFirst();
System.out.println(object);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
[L, U]
- What is the output of this program?
import java.util.*;
public class Linkedlist_Example
{
public static void main(String args[])
{
LinkedList object = new LinkedList();
object.add("O");
object.add("V");
object.add("E");
object.addFirst("L");
System.out.println(object);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
object.addFirst(“L”) method is used to add ‘L’ to the start of a LinkedList object obj.