Deck 14: Generics and the Arraylist Class
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/31
Play
Full screen (f)
Deck 14: Generics and the Arraylist Class
1
To place an element in an ArrayList position for the first time,you usually use the method:
(a)put()
(b)set()
(c)add()
(d)place()
(a)put()
(b)set()
(c)add()
(d)place()
C
2
ArrayList objects do not have the array square-bracket notation.
True
3
Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 for the first time?
(a)recVehicles.set(3,"boat");
(b)recVehicles.set("boat",3);
(c)recVehicles.add(3,"boat");
(d)recVehicles.add("boat",3);
(a)recVehicles.set(3,"boat");
(b)recVehicles.set("boat",3);
(c)recVehicles.add(3,"boat");
(d)recVehicles.add("boat",3);
C
4
A class obtained from a generic class by plugging in a type for the type parameter is said to ________ the generic class.
(a)Inherit
(b)Encapsulate
(c)Instantiate
(d)None of the above
(a)Inherit
(b)Encapsulate
(c)Instantiate
(d)None of the above
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
5
Class and method definitions that include parameters for types are called:
(a)generics
(b)ArrayList
(c)Base type
(d)None of the above
(a)generics
(b)ArrayList
(c)Base type
(d)None of the above
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
6
You can use any primitive type as the base type of an ArrayList class.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
7
All of the following are methods of the ArrayList class except:
(a)length()
(b)size()
(c)set()
(d)get()
(a)length()
(b)size()
(c)set()
(d)get()
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
8
A generic class can be instantiated as any of the following base types except:
(a)Character
(b)Array
(c)String
(d)Double
(a)Character
(b)Array
(c)String
(d)Double
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
9
All of the following are methods of the ArrayList class except:
(a)clear()
(b)resize()
(c)contains()
(d)trimToSize()
(a)clear()
(b)resize()
(c)contains()
(d)trimToSize()
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
10
All of the following are search methods of the ArrayList class except:
(a)isEmpty()
(b)lastIndexOf()
(c)indexOf()
(d)contains()
(a)isEmpty()
(b)lastIndexOf()
(c)indexOf()
(d)contains()
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
11
The keyword ___________ can be used to place a bound on a type parameter.
(a)Implements
(b)Inherits
(c)Encapsulates
(d)Extends
(a)Implements
(b)Inherits
(c)Encapsulates
(d)Extends
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
12
The remove(Object theElement)method of the ArrayList class returns:
(a)Int
(b)Double
(c)Byte
(d)Boolean
(a)Int
(b)Double
(c)Byte
(d)Boolean
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
13
The Java standard libraries have a class named ___________ that behaves almost exactly the same as the class ArrayList.
(a)Array
(b)Container
(c)Vector
(d)All of the above
(a)Array
(b)Container
(c)Vector
(d)All of the above
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
14
All of the following are memory management methods of the ArrayList class except:
(a)ensureCapacity()
(b)clear()
(c)isEmpty()
(d)trimToSize()
(a)ensureCapacity()
(b)clear()
(c)isEmpty()
(d)trimToSize()
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
15
Inheritance is the reason why some parameters of the ArrayList class are of type Base_Type and others of type Object.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
16
To use the Java class ArrayList,you must import the package:
(a)java.awt
(b)java.io
(c)java.util
(d)java.container
(a)java.awt
(b)java.io
(c)java.util
(d)java.container
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
17
When using ArrayLists the method _______ can be used to save memory:
(a)trimToSize()
(b)trimDown()
(c)trimOff()
(d)None of the above
(a)trimToSize()
(b)trimDown()
(c)trimOff()
(d)None of the above
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
18
You can not use the set method to put an element at just any index.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
19
A/An ____________ can change the length while the program is running.
(a)Array
(b)ArrayList
(c)Type parameter
(d)None of the above
(a)Array
(b)ArrayList
(c)Type parameter
(d)None of the above
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
20
An ArrayList object has a fixed size.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
21
What is the base type of the ArrayList defined in question number 2?
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
22
What is a parameterized class?
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
23
The Type parameter is always indicated as a T.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
24
Write Java statements to display the size of the resulting ArrayList from question 5 above.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
25
What are the three main disadvantages of an ArrayList?
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
26
A for loop is an enhanced loop.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
27
The definition of a parameterized class is a class with one or more type parameters.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
28
Write a Java statement to create an ArrayList to hold 25 integers.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
29
The compiler option -Xlint is good for debugging.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
30
You can plug in a primitive type for a type parameter.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck
31
A class definition can have more than one type parameter.
Unlock Deck
Unlock for access to all 31 flashcards in this deck.
Unlock Deck
k this deck