Setting up a Collection
Soon, you will learn more about Collection
and Map
data structures. But first, explore the required import, construction, and parameterization of one of the Collection
types - an ArrayList
.
Diese Übung ist Teil des Kurses
Data Types and Exceptions in Java
Anleitung zur Übung
- Import all the types from the Java Collections Framework package.
- Create a variable called
list
that will hold anArrayList
of strings, using generics to specifyString
onArrayList
. - Set
list
to a new instance ofArrayList
using the parameterized constructorArrayList<String>
.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
// Import all types from Collections Framework package
import ____.____.____;
public class HelloWorld {
public static void main(String[] args) {
// Create a variable for a group of Strings
____<____> list;
// Set the variable to new ArrayList
list = ____ ____<____>();
list.add("hello");
System.out.println(list);
}
}