Deck 14: Generics and the Arraylist Class

Full screen (f)
exit full mode
Question
The keyword ___________ can be used to place a bound on a type parameter.

A)Implements
B)Inherits
C)Encapsulates
D)Extends
Use Space or
up arrow
down arrow
to flip the card.
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)
Question
Inheritance is the reason why some parameters of the ArrayList class are of type Base_Type and others of type Object.
Question
An ArrayList object has a fixed size.
Question
The removeObject theElement)method of the ArrayList class returns:

A)Int
B)Double
C)Byte
D)Boolean
Question
A generic class can be instantiated as any of the following base types except:

A)Character
B)Array
C)String
D)Double
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
Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 for the first time?

A)recVehicles.set3,"boat");
B)recVehicles.set"boat",3);
C)recVehicles.add3,"boat");
D)recVehicles.add"boat",3);
Question
All of the following are memory management methods of the ArrayList class except:

A)ensureCapacity)
B)clear)
C)isEmpty)
D)trimToSize)
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
All of the following are methods of the ArrayList class except:

A)clear)
B)resize)
C)contains)
D)trimToSize)
Question
You can not use the set method to put an element at just any index.
Question
All of the following are methods of the ArrayList class except:

A)length)
B)size)
C)set)
D)get)
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
A/An ____________ can change the length while the program is running.

A)Array
B)ArrayList
C)Type parameter
D)None of the above
Question
ArrayList objects do not have the array square-bracket notation.
Question
You can use any primitive type as the base type of an ArrayList class.
Question
When using ArrayLists the method _______ can be used to save memory:

A)trimToSize)
B)trimDown)
C)trimOff)
D)None of the above
Question
All of the following are search methods of the ArrayList class except:

A)isEmpty)
B)lastIndexOf)
C)indexOf)
D)contains)
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
What are the three main disadvantages of an ArrayList?
Question
You can plug in a primitive type for a type parameter.
Question
The Type parameter is always indicated as a T.
Question
A for loop is an enhanced loop.
Question
Write Java statements to display the size of the resulting ArrayList from question 5 above.
Question
What is a parameterized class?
Question
What is the base type of the ArrayList defined in question number 2?
Question
Write a Java statement to create an ArrayList to hold 25 integers.
Question
Rewrite the following line of code,but use type inference.
ArrayList< Integer > mylist = new ArrayList< Integer >);
Question
A class definition can have more than one type parameter.
Question
The definition of a parameterized class is a class with one or more type parameters.
Question
The compiler option -Xlint is good for debugging.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/32
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 14: Generics and the Arraylist Class
1
The keyword ___________ can be used to place a bound on a type parameter.

A)Implements
B)Inherits
C)Encapsulates
D)Extends
D
2
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
3
Inheritance is the reason why some parameters of the ArrayList class are of type Base_Type and others of type Object.
True
4
An ArrayList object has a fixed size.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
5
The removeObject theElement)method of the ArrayList class returns:

A)Int
B)Double
C)Byte
D)Boolean
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
6
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 32 flashcards in this deck.
Unlock Deck
k this deck
7
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 32 flashcards in this deck.
Unlock Deck
k this deck
8
Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 for the first time?

A)recVehicles.set3,"boat");
B)recVehicles.set"boat",3);
C)recVehicles.add3,"boat");
D)recVehicles.add"boat",3);
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
9
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 32 flashcards in this deck.
Unlock Deck
k this deck
10
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 32 flashcards in this deck.
Unlock Deck
k this deck
11
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 32 flashcards in this deck.
Unlock Deck
k this deck
12
You can not use the set method to put an element at just any index.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
13
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 32 flashcards in this deck.
Unlock Deck
k this deck
14
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 32 flashcards in this deck.
Unlock Deck
k this deck
15
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 32 flashcards in this deck.
Unlock Deck
k this deck
16
ArrayList objects do not have the array square-bracket notation.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
17
You can use any primitive type as the base type of an ArrayList class.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
18
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 32 flashcards in this deck.
Unlock Deck
k this deck
19
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 32 flashcards in this deck.
Unlock Deck
k this deck
20
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 32 flashcards in this deck.
Unlock Deck
k this deck
21
What are the three main disadvantages of an ArrayList?
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
22
You can plug in a primitive type for a type parameter.
Unlock Deck
Unlock for access to all 32 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 32 flashcards in this deck.
Unlock Deck
k this deck
24
A for loop is an enhanced loop.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
25
Write Java statements to display the size of the resulting ArrayList from question 5 above.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
26
What is a parameterized class?
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
27
What is the base type of the ArrayList defined in question number 2?
Unlock Deck
Unlock for access to all 32 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 32 flashcards in this deck.
Unlock Deck
k this deck
29
Rewrite the following line of code,but use type inference.
ArrayList< Integer > mylist = new ArrayList< Integer >);
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
30
A class definition can have more than one type parameter.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
31
The definition of a parameterized class is a class with one or more type parameters.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
32
The compiler option -Xlint is good for debugging.
Unlock Deck
Unlock for access to all 32 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 32 flashcards in this deck.