Setting up a Collection
Soon, you will learn more about Collection and Map data structures. However, first, explore the required import, construction, and parameterization of one of the Collection types, specifically an ArrayList.
Este exercicio faz parte do curso
Data Types and Exceptions in Java
Instruções do exercicio
- Import all the types from the Java Collections Framework package.
- Create a variable called
listthat will hold anArrayListof strings, using generics to specifyStringonArrayList. - Set
listto a new instance ofArrayListusing the parameterized constructorArrayList<String>.
exercicio interativo prático
Tente este exercicio completando este código de exemplo.
// 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);
}
}