Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Data Types and Exceptions in Java

Cursus bekijken

Oefeninstructies

  • Import all the types from the Java Collections Framework package.
  • Create a variable called list that will hold an ArrayList of strings, using generics to specify String on ArrayList.
  • Set list to a new instance of ArrayList using the parameterized constructor ArrayList<String>.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

// 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);
	}
}
Code bewerken en uitvoeren