Deck 14: Generics and the Arraylist Class

Full screen (f)
exit full mode
Question
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()
Use Space or
up arrow
down arrow
to flip the card.
Question
ArrayList objects do not have the array square-bracket notation.
Question
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);
Question
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
Question
Class and method definitions that include parameters for types are called:
(a)generics
(b)ArrayList
(c)Base type
(d)None of the above
Question
You can use any primitive type as the base type of an ArrayList class.
Question
All of the following are methods of the ArrayList class except:
(a)length()
(b)size()
(c)set()
(d)get()
Question
A generic class can be instantiated as any of the following base types except:
(a)Character
(b)Array
(c)String
(d)Double
Question
All of the following are methods of the ArrayList class except:
(a)clear()
(b)resize()
(c)contains()
(d)trimToSize()
Question
All of the following are search methods of the ArrayList class except:
(a)isEmpty()
(b)lastIndexOf()
(c)indexOf()
(d)contains()
Question
The keyword ___________ can be used to place a bound on a type parameter.
(a)Implements
(b)Inherits
(c)Encapsulates
(d)Extends
Question
The remove(Object theElement)method of the ArrayList class returns:
(a)Int
(b)Double
(c)Byte
(d)Boolean
Question
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
Question
All of the following are memory management methods of the ArrayList class except:
(a)ensureCapacity()
(b)clear()
(c)isEmpty()
(d)trimToSize()
Question
Inheritance is the reason why some parameters of the ArrayList class are of type Base_Type and others of type Object.
Question
To use the Java class ArrayList,you must import the package:
(a)java.awt
(b)java.io
(c)java.util
(d)java.container
Question
When using ArrayLists the method _______ can be used to save memory:
(a)trimToSize()
(b)trimDown()
(c)trimOff()
(d)None of the above
Question
You can not use the set method to put an element at just any index.
Question
A/An ____________ can change the length while the program is running.
(a)Array
(b)ArrayList
(c)Type parameter
(d)None of the above
Question
An ArrayList object has a fixed size.
Question
What is the base type of the ArrayList defined in question number 2?
Question
What is a parameterized class?
Question
The Type parameter is always indicated as a T.
Question
Write Java statements to display the size of the resulting ArrayList from question 5 above.
Question
What are the three main disadvantages of an ArrayList?
Question
A for loop is an enhanced loop.
Question
The definition of a parameterized class is a class with one or more type parameters.
Question
Write a Java statement to create an ArrayList to hold 25 integers.
Question
The compiler option -Xlint is good for debugging.
Question
You can plug in a primitive type for a type parameter.
Question
A class definition can have more than one type parameter.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/31
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
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()
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);
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
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
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()
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
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()
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()
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
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
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
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()
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
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
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
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
locked card icon
Unlock Deck
Unlock for access to all 31 flashcards in this deck.