Unknown user Unknown user - 1 year ago 62
Java Question

Creating a new ArrayList in Java

Assuming that I have a class named


And I would like to make a new ArrayList that it's values will be of type

My question is that: How do I do that?

I can't understand from Java Api.

I tried this:

ArrayList<Class> myArray= new ArrayList ArrayList<Class>;

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download