Answers for "array of arraylists in java"

3

how to make an array of arraylists in java

ArrayList<Integer> [] myList = (ArrayList<Integer>[]) new ArrayList[4];
Posted by: Guest on October-12-2020
0

arraylist of arraylist

public static void main(String[] args) {
    ArrayList<ArrayList<Integer>> outer = new ArrayList<ArrayList<Integer>>();
    ArrayList<Integer> inner = new ArrayList<Integer>();        

    inner.add(100);     
    inner.add(200);
    outer.add(inner); // add first list
    inner = new ArrayList<Integer>(inner); // create a new inner list that has the same content as  
                                           // the original inner list
    outer.add(inner); // add second list

    outer.get(0).add(300); // changes only the first inner list

    System.out.println(outer);
}
Posted by: Guest on September-23-2020

Code answers related to "array of arraylists in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language