I have a class Gerbil that I use to test my code. In main I want to make an array of type Gerbil and then perform some operations on it starting with creating a sublist from the main list of objects. Here’s my code:
import java.awt.List;
import java.util.ArrayList;
public class HelloWorld {
public static void main(String[] args) {
List<Gerbil> hs = new ArrayList<Gerbil>();
for(int i = 0; i<10; i++){
hs.add(new Gerbil(i));
}
for(Gerbil i : hs) {
i.hop();
}
}
}
I get error for List<Gerbil> saying that The type List is ont of generic type... I understand the meaning of the error but that makes me wonder what is the right way to do this?
You need to use
java.util.Listfrom the Collections API: