Your first statement
ArrayList[] arraylist=new ArrayList[2];
allocates an array object that can reference two ArrayList
(s). It doesn't instantiate those ArrayList
(s). And raw-types are a bad idea. But you could add something like,
ArrayList[] arraylist = new ArrayList[2];
arraylist[0] = new ArrayList();
arraylist[1] = new ArrayList();
And I get
[Ngyen, Van, Jone]
[20, 40, 28]
But the above has no type safety. As you added String
and Integer
instances to the two List
(s).
No comments:
Post a Comment