ArrayList<>[] al = new Arraylist[3];
ArrayList[] al = new Arraylist[3]();
ArrayList<String>[] al = new Arraylist<String>[3]();
ArrayList<Actor>[] al = new Arraylist<Actor>[3]();
al[6].add("Sylvester","Stallone");
al[5].add(new Actor("Sylvester", "Stallone"));
int[] array = new int[3];
ArrayList<String>[] al = new ArrayList<String>[3];
al[0] = new ArrayList<String>();
al[1] = new ArrayList<String>();
al[2] = new ArrayList<String>();

ArrayList<String>[] al = new ArrayList<String>[3]();
ArrayList
public ArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.
Parameters:
initialCapacity - the initial capacity of the list.
Throws:
IllegalArgumentException - if the specified initial capacity is negative
ArrayList
public ArrayList()
Constructs an empty list with an initial capacity of ten.
ArrayList
public ArrayList(Collection c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. The ArrayList instance has an initial capacity of 110% the size of the specified collection.
Parameters:
c - the collection whose elements are to be placed into this list.
ArrayList<String>[] al = new ArrayList<String>[3];
al[0] = new ArrayList<String>();
al[1] = new ArrayList<String>();
al[2] = new ArrayList<String>();
generic array creation
ArrayList<String>[] al = new ArrayList<String>[3];
^
ArrayList a1[] = new ArrayList[3];
a1[0] = new ArrayList<String>();
a1[1] = new ArrayList<String>();
a1[2] = new ArrayList<String>();

ArrayList[] al = new ArrayList[3];
al[0]=new ArrayList<Actor>();
al[1]=new ArrayList<Actor>();
al[2]=new ArrayList<Actor>();
al[0].add(new Actor("Sylvester","Stalone"));
^^^^^^Produces a warning^^^^^^^^^
System.out.println(al[0].get(0).fname);
class Actor {
public String fname;
public String lname;
public Actor(String x, String y) {
fname=x;
lname=y;
}
}
class Actor {
public String fname;
public String lname;
public Actor(String x, String y) {
fname=x;
lname=y;
}
public String fname(){
return fname;
}
}
System.out.println(al[0].get(0).fname());
hmm, still doesn't work. it still "can't find symbol".
this is doing my head in!!
ArrayList[] al = new ArrayList[3];
al[0]=new ArrayList<Actor>();
al[1]=new ArrayList<Actor>();
al[2]=new ArrayList<Actor>();
al[0].add(new Actor("Sylvester","Stalone"));
System.out.println(al[0].get(0).fname());
class Actor {
public String fname;
public String lname;
public Actor(String x, String y) {
fname=x;
lname=y;
}
public String fname(){
return fname;
}
}
javac MyArrayListExample.java Actor.java
cannot find symbol
symbol : method fname()
location: class java.lang.Object
System.out.println(al[0].get(0).fname());
^
1 error
warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
al[0].add(new Actor("Sylvester","Stalone"));
^
1 warning