Deck 16: Collections,maps,and Iterators
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/44
Play
Full screen (f)
Deck 16: Collections,maps,and Iterators
1
To change an existing element of a vector you must use the __________ method.
A)add)
B)set)
C)change)
D)mutate)
A)add)
B)set)
C)change)
D)mutate)
B
2
If you want a class that implements the Map interface and do not need any methods beyond those in the Map interface,you can use the ____________ class.
A)Vector< T >
B)AbstractMap< K,V >
C)HashMap< K,V >
D)HashSet< T >
A)Vector< T >
B)AbstractMap< K,V >
C)HashMap< K,V >
D)HashSet< T >
C
3
The Collection class or interface that allows only unique elements is the ___________ class or interface.
A)List< T >
B)Set< T >
C)Vector< T >
D)all of the above
A)List< T >
B)Set< T >
C)Vector< T >
D)all of the above
B
4
If you do not need efficient random access but need to efficiently move sequentially through the list,then use the _____________ class.
A)Vector< T >
B)LinkedList< T >
C)HashSet< T >
D)TreeSet< T >
A)Vector< T >
B)LinkedList< T >
C)HashSet< T >
D)TreeSet< T >
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
5
All of the following are methods of the Iterator interface except:
A)clear)
B)hasNext)
C)next)
D)remove)
A)clear)
B)hasNext)
C)next)
D)remove)
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
6
The primary interface/interfaces for a collection class is/are:
A)Collection< T >
B)Set< T >
C)List< T >
D)All of the above
A)Collection< T >
B)Set< T >
C)List< T >
D)All of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
7
If you want a class that implements the List interface and do not need any methods beyond those in the List interface,you can use the ____________ class.
A)Vector< T >
B)LinkedList< T >
C)HashSet< T >
D)TreeSet< T >
A)Vector< T >
B)LinkedList< T >
C)HashSet< T >
D)TreeSet< T >
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
8
A Java collection is any class that implements the Collection interface.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
9
A collection is a data structure for holding elements.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
10
All of the following are members of Java's Collection class except:
A)Queue< T >
B)LinkedList< T >
C)Vector< T >
D)Set< T >
A)Queue< T >
B)LinkedList< T >
C)Vector< T >
D)Set< T >
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
11
The method ___________ can be used to determine the number of elements in an ArrayList.
A)length)
B)vectorLength)
C)size)
D)vectorSize)
A)length)
B)vectorLength)
C)size)
D)vectorSize)
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
12
A ___________ is used to specify a wide range of parameters.
A)Collection
B)Iterator
C)Vector
D)Wildcard
A)Collection
B)Iterator
C)Vector
D)Wildcard
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
13
The interface SortedSet and the concrete class _________ is designed for implementations of the Set interface that provide for rapid retrieval of elements.
A)Vector< T >
B)LinkedList< T >
C)HashSet< T >
D)TreeSet< T >
A)Vector< T >
B)LinkedList< T >
C)HashSet< T >
D)TreeSet< T >
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
14
The hasNext)method of the Iterator interface has a return value of:
A)byte
B)int
C)boolean
D)none of the above
A)byte
B)int
C)boolean
D)none of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
15
A ____________ is a data structure for holding elements.
A)Collection
B)Iterator
C)Vector
D)Wildcard
A)Collection
B)Iterator
C)Vector
D)Wildcard
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
16
All of the following methods are part of the Collection< T > interface except:
A)Contains)
B)toArray)
C)retainAll)
D)toString)
A)Contains)
B)toArray)
C)retainAll)
D)toString)
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
17
To use Java's Vector class,you must import the ___________ package.
A)java.Math
B)java.Exception
C)java.util
D)java.lang
A)java.Math
B)java.Exception
C)java.util
D)java.lang
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
18
The method containsObject o)of the ArrayList class returns a value of type:
A)int
B)char
C)byte
D)boolean
A)int
B)char
C)byte
D)boolean
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
19
Memory management methods of the vector class include all of the following except:
A)remove)
B)trimToSize)
C)capacity)
D)size)
A)remove)
B)trimToSize)
C)capacity)
D)size)
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
20
If you want a class that implements the Set interface and do not need any methods beyond those in the Set interface,you can use the concrete class:
A)Vector< T >
B)LinkedList< T >
C)HashSet< T >
D)TreeSet< T >
A)Vector< T >
B)LinkedList< T >
C)HashSet< T >
D)TreeSet< T >
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
21
Elements of a vector must be of a primitive type,such as int,double,or char.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
22
An Iterator is an object that allows your code to produce the elements in a vector or other container one after the other,exactly once.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
23
For-each loops can not be used with Collection classes.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
24
What must you do before adding a primitive type to a vector?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
25
What is the difference between a vector's size and a vector's capacity?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
26
All Collection classes are part of the java.util package.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
27
Write a Java statement to recover the unused memory in the resulting vector in number 4 above.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
28
The number of entries that may be added to a HashMap< K,V > object is limited to what is specified as the initial capacity in the constructor for the HashMap< K,V > object.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
29
Write a Java statement to create a vector with initial capacity of 50.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
30
Write a Java statement that changes the value of element 27 to 5.0 in the resulting vector in number 3 above.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
31
< T > is a wildcard used to specify a wide range of parameters.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
32
The AbstractSequentialList class provides efficient implementation of sequentially moving through the list at the expense of having inefficient implementation of random access to elements.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
33
The List interface is for collections that allow repetition of elements and do not impose an order on their elements.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
34
Classes that implement the Set interface allows duplicate elements to occur.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
35
The difference between the List< T > interface and the Set< T > interface is that the Set< T > interface does not impose an order on its unique elements.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
36
The V parameter in a HashMap< K,V > may be any object,but the K parameter must be a String.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
37
A vector can potentially encounter an ArrayIndexOutOfBoundsException.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
38
Create a for loop to initially set the values of the vector created in number 1 above to the value of negative 1.0.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
39
Write a Java statement to resize the resulting vector in number 2 above to 100.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
40
When an interface lists a method as "optional," you do not need to implement it when defining a class that implements the interface.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
41
Write a method named displayList)that has one parameter of type Vector and has a return value of void.The method uses an iterator to display the contents of the Vector.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
42
Compare and contrast vectors and arrays.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
43
How can one retrieve all the values of a HashMap object?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
44
What is the purpose of the Java Iterator interface?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck