简体   繁体   中英

How to declare multiple arraylists in Java

I want to declare multiple arraylists but i failed to do so. Is there a way to it? here's my failed code:

List<Integer>[] table = new ArrayList<Integer>[]();

It seems no matter how and where do i put '[]' , it just doesn't work. any help or suggestion would be appreciated

You have to specify the size like this:

ArrayList<Integer>[] table = new ArrayList[10];

Creates an array of ArrayList with capacity of 10.

@SuppressWarnings("unchecked")
List<Integer>[] table = (ArrayList<Integer>[]) Array.newInstance(ArrayList.class, size);
List<Integer> multiple = new ArrayList<String>(), myArray = new ArrayList<String>();

希望能帮助到你。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM