Test Your Understanding - Collection and Generics - Attempt Review
Test Your Understanding - Collection and Generics - Attempt Review
Dashboard / Programming using Java / Hands On - Collection, Generics and Stream API / Test Your Understanding - Collection and Generics
Question
int[] myArray = new int[] {1, 2, 3, 4, 5};
1 What allows you to create a list from this array?
Correct
Select one:
List myList = Collections.fromArray(myArray);
Question
2 java.util.Map interface provides the capability to store objects using a key-value pair ?
Correct
Question
Which two statements are true about the hashCode method?
3
Correct
The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.
The hashCode method is used by the java.util.SortedSet collection class to order the elements within that set.
The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a
Gaussian distribution.
The correct answers are: The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that
class., The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for
swift retrieval.
Question
Given:
4 11. public class Person {
Correct
12. private String name;
Mark 1.00 out of
1.00 13. public Person(String name) {
15. }
18. }
19. }
Select one:
The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.
The time to nd the value from HashMap with a Person key depends on the size of the map.
Inserting a second Person object into a HashSet will cause the rst Person object to be removed as a duplicate.
Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.
The correct answer is: The time to nd the value from HashMap with a Person key depends on the size of the map.
VIRAG NIMESHKUMAR DOSA…
Question
Given
5 1. import java.util.*;
Correct
2. public class WrappedString {
Mark 1.00 out of
1.00 3. private String s;
12. System.out.println(hs.size()); } }
Select one:
3
Question
6 nextIndex() and previousIndex() are methods of ListIterator interface
Correct