Creating a new ArrayList in Java
If you just want a list:
ArrayList<Class> myList = new ArrayList<Class>();
If you want an arraylist of a certain length (in this case size 10):
List<Class> myList = new ArrayList<Class>(10);
If you want to program against the interfaces (better for abstractions reasons):
List<Class> myList = new ArrayList<Class>();
Programming against interfaces is considered better because it's more abstract. You can change your Arraylist with a different list implementation (like a LinkedList) and the rest of your application doesn't need any changes.
You are looking for Java generics
List<MyClass> list = new ArrayList<MyClass>();
Here's a tutorial http://docs.oracle.com/javase/tutorial/java/generics/index.html
You're very close. Use same type on both sides, and include ()
.
ArrayList<Class> myArray = new ArrayList<Class>();