Show List

Quiz - Java Collections - 2

57%

Public Average Score
Select the right answer for below questions:

What is the difference between an Iterator and a ListIterator in Java?
An Iterator can traverse a collection in only one direction, while a ListIterator can traverse a collection in both directions
A ListIterator can traverse a collection in only one direction, while an Iterator can traverse a collection in both directions
Both Iterator and ListIterator can traverse a collection in only one direction
None of the above
An Iterator can traverse a collection in only one direction, while a ListIterator can traverse a collection in both directions

Can a Map in Java be converted to a List?
Yes, using the map.values().toArray() method
Yes, using the map.entrySet().toArray() method
Yes, using the map.keySet().toArray() method
Yes, using all of the above methods
Yes, using the map.entrySet().toArray() method

Can a List in Java be converted to a Map?
Yes, using the list.toArray().collect(Collectors.toMap()) method
Yes, using the list.entrySet().collect(Collectors.toMap()) method
No, a List cannot be converted to a Map
Yes, using the list.stream().collect(Collectors.toMap()) method
Yes, using the list.stream().collect(Collectors.toMap()) method

Can a Set in Java be converted to a List?
Yes, using the set.toArray().toList() method
Yes, using the set.stream().collect(Collectors.toList()) method
Yes, using the set.entrySet().toList() method
No, a Set cannot be converted to a List
Yes, using the set.stream().collect(Collectors.toList()) method

What is the difference between a HashSet and a TreeSet in Java?
A HashSet uses a hash table for storage, while a TreeSet uses a tree for storage
A TreeSet uses a hash table for storage, while a HashSet uses a tree for storage
Both HashSet and TreeSet use hash tables for storage
None of the above
A HashSet uses a hash table for storage, while a TreeSet uses a tree for storage

Can a Map in Java store a null key or value?
Yes, a Map can store a null key or value
Yes, a Map can store a null key but not a null value
Yes, a Map can store a null value but not a null key
No, a Map cannot store a null key or value
No, a Map cannot store a null key or value

What is the difference between a HashMap and a TreeMap in Java?
A HashMap uses a hash table for storage, while a TreeMap uses a tree for storage
A TreeMap uses a hash table for storage, while a HashMap uses a tree for storage
Both HashMap and TreeMap use hash tables for storage
None of the above
A HashMap uses a hash table for storage, while a TreeMap uses a tree for storage

What is the difference between a LinkedList and an ArrayList in Java?
An ArrayList is implemented using linked nodes, while a LinkedList is implemented using an array
Both LinkedList and ArrayList are implemented using linked nodes
A LinkedList is implemented using linked nodes, while an ArrayList is implemented using an array
None of the above
A LinkedList is implemented using linked nodes, while an ArrayList is implemented using an array

Can an ArrayList in Java be sorted?
Yes, using the ArrayList.sort() method
Yes, using the ArrayList.sort(Comparator) method
Yes, using both ArrayList.sort() and ArrayList.sort(Comparator) methods
No, an ArrayList cannot be sorted
Yes, using the ArrayList.sort(Comparator) method

What is the default size of the HashSet in Java?
10
16
8
It is not specified
It is not specified

Submit
Retry
{"qz1-628203":"An Iterator can traverse a collection in only one direction, while a ListIterator can traverse a collection in both directions","qz1-628204":"Yes, using the map.entrySet().toArray() method","qz1-628205":"Yes, using the list.stream().collect(Collectors.toMap()) method","qz1-628206":"Yes, using the set.stream().collect(Collectors.toList()) method","qz1-628207":"A HashSet uses a hash table for storage, while a TreeSet uses a tree for storage","qz1-628208":"No, a Map cannot store a null key or value","qz1-628209":"A HashMap uses a hash table for storage, while a TreeMap uses a tree for storage","qz1-628210":"A LinkedList is implemented using linked nodes, while an ArrayList is implemented using an array","qz1-628211":"Yes, using the ArrayList.sort(Comparator) method","qz1-628212":"It is not specified"}

    Leave a Comment


  • captcha text