Is it possible to init an Array of two ArrayLists as a class field in Java?
Now I have the following. In the fields declaration:
public ArrayList someArray[] = new ArrayList[2];
and later in one of methods the actual assigning:
someArray[0] = new ArrayList<String>();
someArray[1] = new ArrayList<String>();
It can be done :
public ArrayList<String[]>[]
someArray = new ArrayList[] {new ArrayList<String[]>(),new ArrayList<String[]>()};
Edited after clarification from OP.
尝试这个:
public ArrayList[] arrayOfArrayLists = new ArrayList[]{new ArrayList<String>() , 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.