Deck 18: Collections
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
Play
Full screen (f)
Deck 18: Collections
1
An object that is used to retrieve objects from a collection is called
A) an iterator
B) a collector
C) an accessor
D) All of the above
A) an iterator
B) a collector
C) an accessor
D) All of the above
A
2
A collection that does not impose a positional order on its elements,and does not allow duplicates is called a
A) set
B) linked list
C) non-positional map
D) hash map
A) set
B) linked list
C) non-positional map
D) hash map
A
3
The concrete classes that implement the List interface are
A) AbstractList,AbstractSequentialList,and List
B) LinkedList,ArrayList,and AbstractList
C) LinkedList,ArrayList,and Vector
D) None of the above
A) AbstractList,AbstractSequentialList,and List
B) LinkedList,ArrayList,and AbstractList
C) LinkedList,ArrayList,and Vector
D) None of the above
C
4
Which of the following is true?
A) The ListIterator interface is a subinterface of the Iterator interface
B) The ListIterator interface is a superinterface of the Iterator interface
C) The ListIterator interface extends the List interface
D) None of the above
A) The ListIterator interface is a subinterface of the Iterator interface
B) The ListIterator interface is a superinterface of the Iterator interface
C) The ListIterator interface extends the List interface
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following is true?
A) The retrieve()method of an iterator can only be called after isEmpty()has returned false
B) The remove(.method of an iterator can only be called after next(.has been called
C) Any iterator can move forward as well as backwards through a collection
D) Once an iterator has reached the end of the collection,calling any of its methods will throw a NoSuchElement exception
A) The retrieve()method of an iterator can only be called after isEmpty()has returned false
B) The remove(.method of an iterator can only be called after next(.has been called
C) Any iterator can move forward as well as backwards through a collection
D) Once an iterator has reached the end of the collection,calling any of its methods will throw a NoSuchElement exception
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
When the next( )method of Iterator is called at the end of a collection,it
A) throws NoSuchElementException
B) returns null
C) wraps around to the beginning of the collection and returns the first element
D) returns the a copy of the last element returned
A) throws NoSuchElementException
B) returns null
C) wraps around to the beginning of the collection and returns the first element
D) returns the a copy of the last element returned
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
An entry in a map
A) is called a mapping
B) associates a key with a value
C) may not share a key value with any other entry in the map
D) All of the above
A) is called a mapping
B) associates a key with a value
C) may not share a key value with any other entry in the map
D) All of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
The ListIterator interface
A) specializes the Iterator interface to work with lists,but adds no new methods
B) adds to Iterator the ability to move backwards in the collection
C) adds to Iterator the ability to iterate over several collections,if those collections are lists
D) None of the above
A) specializes the Iterator interface to work with lists,but adds no new methods
B) adds to Iterator the ability to move backwards in the collection
C) adds to Iterator the ability to iterate over several collections,if those collections are lists
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
An index
A) is a list of keys that allows fast look up of values in a map
B) is an object that indicates which one of a group of collections contains a given value
C) is the position of an element within a list
D) is used with generic collections to quickly find stored values
A) is a list of keys that allows fast look up of values in a map
B) is an object that indicates which one of a group of collections contains a given value
C) is the position of an element within a list
D) is used with generic collections to quickly find stored values
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
The Vector class
A) is an abstract class that is a superclass for ArrayList
B) works just like ArrayList,except it is synchronized
C) implements the Set Interface
D) None of the above
A) is an abstract class that is a superclass for ArrayList
B) works just like ArrayList,except it is synchronized
C) implements the Set Interface
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
A LinkedList is the right kind of list to use when
A) most of the elements added to the list are being added at the end
B) there are lots of insertions and deletions in the middle of the list
C) elements are added to the list in groups of twos,threes,or more
D) each element added is a reference to another item
A) most of the elements added to the list are being added at the end
B) there are lots of insertions and deletions in the middle of the list
C) elements are added to the list in groups of twos,threes,or more
D) each element added is a reference to another item
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
The three major categories of Java collections are
A) lists,sets,and maps
B) hash lists,hash tables,and sets
C) sets,collections,and maps
D) tree sets,list sets,and hash maps
A) lists,sets,and maps
B) hash lists,hash tables,and sets
C) sets,collections,and maps
D) tree sets,list sets,and hash maps
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
A collection whose elements are pairs of keys and values is called
A) an enumerator
B) a map
C) a hash list
D) a paired collection
A) an enumerator
B) a map
C) a hash list
D) a paired collection
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following is true?
A) Both the Set and List interfaces extend the Collection interface
B) Both the Set and Map interfaces extend the Collection interface
C) Both the List and Map interfaces extend the Collection interface
D) None of the above
A) Both the Set and List interfaces extend the Collection interface
B) Both the Set and Map interfaces extend the Collection interface
C) Both the List and Map interfaces extend the Collection interface
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
A collection that stores its elements in an (ordered)sequence,and allows access to each element by its position in the sequence is called a
A) map
B) positional map
C) ordered set
D) list
A) map
B) positional map
C) ordered set
D) list
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
A collection that is synchronized
A) protects data from corruption when the data is accessed by multiple threads
B) is associated with a timer object that controls access to data in the collection
C) is exemplified by ArrayList,HashMap,and Vector
D) None of the above
A) protects data from corruption when the data is accessed by multiple threads
B) is associated with a timer object that controls access to data in the collection
C) is exemplified by ArrayList,HashMap,and Vector
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
If you try to add an item to an ArrayList whose size is equal to its capacity,
A) an exception that indicates that the ArrayList is full is thrown
B) a new ArrayList object with twice the capacity is created,and the elements are moved to this new ArrayList.
C) The method for adding the new item returns false
D) The method for adding the new item returns null
A) an exception that indicates that the ArrayList is full is thrown
B) a new ArrayList object with twice the capacity is created,and the elements are moved to this new ArrayList.
C) The method for adding the new item returns false
D) The method for adding the new item returns null
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following is true?
A) A set allows duplicate values to be stored
B) A map allows duplicate keys to be stored
C) No Java collection allows duplicate values to be stored
D) A list allows duplicate values to be stored
A) A set allows duplicate values to be stored
B) A map allows duplicate keys to be stored
C) No Java collection allows duplicate values to be stored
D) A list allows duplicate values to be stored
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
A Java collection
A) is a class that is defined in the java.awt package
B) is an abstract class in the java.collect package
C) is an object that is is used as a container for other objects
D) None of the above
A) is a class that is defined in the java.awt package
B) is an abstract class in the java.collect package
C) is an object that is is used as a container for other objects
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
The Iterator interface
A) is defined in the java.awt package
B) is defined in the javax.swing package
C) has next(.,isEmpty(.,and retrieve(.methods
D) has next(.,hasNext(.,and remove(.methods
A) is defined in the java.awt package
B) is defined in the javax.swing package
C) has next(.,isEmpty(.,and retrieve(.methods
D) has next(.,hasNext(.,and remove(.methods
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
If different objects can have the same hash code,then
A) some HashSet buckets may have more than one object
B) the HashSet add method will throw an IllegalStateException
C) the operation of searching a HashSet becomes more efficient
D) None of the above
A) some HashSet buckets may have more than one object
B) the HashSet add method will throw an IllegalStateException
C) the operation of searching a HashSet becomes more efficient
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
A hashcode of an object
A) is the value returned when you store the object into a HashSet collection
B) is an integer that can be used to characterize an object and help identify it
C) is useful when storing objects in HashMaps,HashSets,and Lists
D) None of the above
A) is the value returned when you store the object into a HashSet collection
B) is an integer that can be used to characterize an object and help identify it
C) is useful when storing objects in HashMaps,HashSets,and Lists
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
The load factor of a HashSet
A) increases as elements are added,and decreases as elements are removed
B) is the fraction of the capacity that must be filled before the capacity is increased
C) is the fraction of the capacity that is available to be filled with new elements
D) needs to be kept low to ensure good performance
A) increases as elements are added,and decreases as elements are removed
B) is the fraction of the capacity that must be filled before the capacity is increased
C) is the fraction of the capacity that is available to be filled with new elements
D) needs to be kept low to ensure good performance
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following is true?
A) All hashing algorithms give different hash codes to different objects,and the same hash code to equal objects
B) A hash code of a Number object may be a float,an int,or a double
C) Any application that overrides the Object hashCode method should also override the equals method
D) Any application that overrides the Object equals method should also override the hashCode method
A) All hashing algorithms give different hash codes to different objects,and the same hash code to equal objects
B) A hash code of a Number object may be a float,an int,or a double
C) Any application that overrides the Object hashCode method should also override the equals method
D) Any application that overrides the Object equals method should also override the hashCode method
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
Collections
A) is the interface from which all collection interfaces are derived
B) is the superclass of all abstract and concrete collection classes
C) is a class that contains static methods for working with collections
D) None of the above
A) is the interface from which all collection interfaces are derived
B) is the superclass of all abstract and concrete collection classes
C) is a class that contains static methods for working with collections
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
When using a HashSet
A) you should override the hashCode method defined in the Object class
B) you should override the equals method defined in the Object class
C) you should override the hashCode and equals methods defined in the Object class
D) you should override the hashCode,equals,and clone methods defined in the Object class
A) you should override the hashCode method defined in the Object class
B) you should override the equals method defined in the Object class
C) you should override the hashCode and equals methods defined in the Object class
D) you should override the hashCode,equals,and clone methods defined in the Object class
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
Comparable
A) is a class that allows two objects to be compared
B) is an interface implemented by classes that need to impose a natural order on instance objects
C) is a library class method that is used by certain sorting packages
D) None of the above
A) is a class that allows two objects to be compared
B) is an interface implemented by classes that need to impose a natural order on instance objects
C) is a library class method that is used by certain sorting packages
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
A procedure for obtaining a hashcode from an object is called
A) a hashing algorithm
B) an encoder
C) a hashing encoder
D) a hashcoder
A) a hashing algorithm
B) an encoder
C) a hashing encoder
D) a hashcoder
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
A TreeSet
A) is like a Set,only it is faster
B) is a Set that allows elements to be retrieved in the order added
C) is a Set that organizes its elements in a tree according to the inheritance hierarchy of the elements
D) is like a Set that allows elements to be retrieved according to their natural order,or according to an order specified by a Comparator
A) is like a Set,only it is faster
B) is a Set that allows elements to be retrieved in the order added
C) is a Set that organizes its elements in a tree according to the inheritance hierarchy of the elements
D) is like a Set that allows elements to be retrieved according to their natural order,or according to an order specified by a Comparator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
The default implementation of hashCode in Java returns
A) a value determined from the class type of the object
B) a value derived from the memory address of the object
C) a value determined from the values of the fields in the object
D) None of the above
A) a value determined from the class type of the object
B) a value derived from the memory address of the object
C) a value determined from the values of the fields in the object
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
A LinkedHashMap
A) can be set up to maintain its keys in insert or access order
B) is an unordered collection that provides no control over the order of retrieval of stored elements
C) provides an iterator that can be used to retrieve its elements
D) None of the above
A) can be set up to maintain its keys in insert or access order
B) is an unordered collection that provides no control over the order of retrieval of stored elements
C) provides an iterator that can be used to retrieve its elements
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following is true of a HashSet object?
A) Increasing the capacity of the HashSet usually has no effect on the number of collisions
B) The time required to add an element,or search for an element,is unaffected by the number of collisions
C) The time required to add an element,or search for an element,decreases as the number of collisions increases
D) The time required to add an element,or search for an element,increases as the number of collisions increases
A) Increasing the capacity of the HashSet usually has no effect on the number of collisions
B) The time required to add an element,or search for an element,is unaffected by the number of collisions
C) The time required to add an element,or search for an element,decreases as the number of collisions increases
D) The time required to add an element,or search for an element,increases as the number of collisions increases
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
One way to iterate through a Map is
A) to obtain the Map's iterator and use it
B) to obtain the set of keys for the stored elements,and then iterate through that set of keys
C) to use an integer index in a for loop to step through the elements
D) None of the above
A) to obtain the Map's iterator and use it
B) to obtain the set of keys for the stored elements,and then iterate through that set of keys
C) to use an integer index in a for loop to step through the elements
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
LinkedHashSet differs from HashSet because
A) the LinkedHashSet stores objects that have the same hash code in the same bucket
B) the LinkedHashSet is a subclass of TreeSet
C) the LinkedHashSet allows elements to be retrieved in the same order as they were added
D) the LinkedHashSet is a subclass of LinkedList
A) the LinkedHashSet stores objects that have the same hash code in the same bucket
B) the LinkedHashSet is a subclass of TreeSet
C) the LinkedHashSet allows elements to be retrieved in the same order as they were added
D) the LinkedHashSet is a subclass of LinkedList
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
A collision occurs when
A) objects whose class types are not related through inheritance have the same hashcode
B) objects instantiated from different generic types have the same hashcode
C) objects whose class types are not related through inheritance have hashcodes one of which divides the other
D) objects whose values are not equal have the same hash code
A) objects whose class types are not related through inheritance have the same hashcode
B) objects instantiated from different generic types have the same hashcode
C) objects whose class types are not related through inheritance have hashcodes one of which divides the other
D) objects whose values are not equal have the same hash code
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
A HashMap
A) is a subclass of Map that implements the HashCode interface
B) is a subclass of HashSet that implements the Map interface
C) uses hash codes to store keys
D) None of the above
A) is a subclass of Map that implements the HashCode interface
B) is a subclass of HashSet that implements the Map interface
C) uses hash codes to store keys
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Comparable
A) specifies a single method,compareTo
B) specifies three methods,compareTo,compare,and equals
C) specifies two methods,compare and equals
D) specifies two methods,compare and compareTo
A) specifies a single method,compareTo
B) specifies three methods,compareTo,compare,and equals
C) specifies two methods,compare and equals
D) specifies two methods,compare and compareTo
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
Comparator
A) specifies a single method,compareTo
B) specifies three methods,compareTo,compare,and equals
C) specifies two methods,compare and equals
D) specifies two methods,compare and compareTo
A) specifies a single method,compareTo
B) specifies three methods,compareTo,compare,and equals
C) specifies two methods,compare and equals
D) specifies two methods,compare and compareTo
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
Ideally,the hashcodes of two objects
A) should be equal when the objects are equal,and different when the objects have different values
B) should be equal then the objects belong to the same class,and be different when the objects belong to different classes
C) should be equal when the objects are instantiated with the same type from the same generic class
D) should divide each other only when the class of one of the objects extends the class of the other
A) should be equal when the objects are equal,and different when the objects have different values
B) should be equal then the objects belong to the same class,and be different when the objects belong to different classes
C) should be equal when the objects are instantiated with the same type from the same generic class
D) should divide each other only when the class of one of the objects extends the class of the other
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following is true?
A) A TreeSet created with the no-arg constructor expects its elements to implement the Comparable interface
B) A TreeSet created with the no-arg constructor expects its elements to implement the Comparator interface
C) The load factor of Tree Set should never exceed 50% to ensure maximum performance
D) The load factor of Tree Set should never exceed 75% to ensure maximum performance
A) A TreeSet created with the no-arg constructor expects its elements to implement the Comparable interface
B) A TreeSet created with the no-arg constructor expects its elements to implement the Comparator interface
C) The load factor of Tree Set should never exceed 50% to ensure maximum performance
D) The load factor of Tree Set should never exceed 75% to ensure maximum performance
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
The enhanced for loop,when used on a collection,
A) is converted by the compiler to a traditional loop that uses an iterator
B) should be avoided because it incurs runtime overhead
C) throws an runtime exception
D) None of the above
A) is converted by the compiler to a traditional loop that uses an iterator
B) should be avoided because it incurs runtime overhead
C) throws an runtime exception
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Which of the following is true?
A) The Map interface extends the Collection interface
B) The Map interface does not extend the Collection interface
C) The HashMap interface extends the Map interface
D) The Map interface extends the Set interface
A) The Map interface extends the Collection interface
B) The Map interface does not extend the Collection interface
C) The HashMap interface extends the Map interface
D) The Map interface extends the Set interface
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
In a Map object
A) It is possible for a single key to appear more than once,with different values
B) It is possible for a single key to appear more than once,even with the same values
C) It is possible for a single value to appear more than once,with different keys
D) It is possible for a single value to appear more than once,even with the same key
A) It is possible for a single key to appear more than once,with different values
B) It is possible for a single key to appear more than once,even with the same values
C) It is possible for a single value to appear more than once,with different keys
D) It is possible for a single value to appear more than once,even with the same key
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
The ListIterator method that replaces an existing element with a new element is
A) set
B) replace
C) overwrite
D) add
A) set
B) replace
C) overwrite
D) add
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
Which of the following is true?
A) Collections that implement the SortedMap interface do not support generic types
B) Collections that implement the Collection interface do not support generic types
C) Collections that implement the Map interface do not support generic types
D) All of the collections in the JCF support generic types
A) Collections that implement the SortedMap interface do not support generic types
B) Collections that implement the Collection interface do not support generic types
C) Collections that implement the Map interface do not support generic types
D) All of the collections in the JCF support generic types
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
ListIterator is a subinterface of
A) Collection
B) Iterator
C) List
D) Comparator
A) Collection
B) Iterator
C) List
D) Comparator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
The code
List< String > myLs = new ArrayList< String >( );
Uses a List < String > interface variable to reference the concrete ArrayList< String > object.
The advantage of doing this is
A) the class of the collection object can later be changed to LinkedList,or even Vector,without needing to change anything else in the program
B) the class of the collection object can later be changed to LinkedList,Vector,TreeSet,or even HashSet,without needing to change anything else in the program
C) the program compiles faster
D) None of the above: the statement is a type error.
List< String > myLs = new ArrayList< String >( );
Uses a List < String > interface variable to reference the concrete ArrayList< String > object.
The advantage of doing this is
A) the class of the collection object can later be changed to LinkedList,or even Vector,without needing to change anything else in the program
B) the class of the collection object can later be changed to LinkedList,Vector,TreeSet,or even HashSet,without needing to change anything else in the program
C) the program compiles faster
D) None of the above: the statement is a type error.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
An object that can compare two other objects and determine whether one is greater than,less than,or equal to the other is a
A) Comparator
B) Comparable
C) Sorter
D) Sequencer
A) Comparator
B) Comparable
C) Sorter
D) Sequencer
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
A collection suitable for use in an application with multiple threads accessing a list is
A) ArrayList
B) LinkedList
C) HashSet
D) Vector
A) ArrayList
B) LinkedList
C) HashSet
D) Vector
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
The concrete classes of the JCF that implement the Set interface
A) all extend the AbstractMap class
B) should be assigned the value null when they are empty collections
C) are optimized for fast searching of elements in a collection
D) None of the above
A) all extend the AbstractMap class
B) should be assigned the value null when they are empty collections
C) are optimized for fast searching of elements in a collection
D) None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck