I am trying to store user input into ArrayList of ArrayList.
ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>();
For example, storing it as [[1,2,3],[4,5],[6,1,8]]
Below is my code,
Scanner input = new Scanner(System.in);
System.out.println("Enter a set of numbers:");
String line = input.nextLine();
String[] numbers = line.split(" +");
ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>();
ArrayList<Integer> a1 = new ArrayList<Integer>();
for(int i=0; i<numbers.length; i++) {
a1.add(new Integer(numbers[i]));
}
a.add(a1);
But then when I types it in to terminal, it becomes [[1,2,3,4,5,6,1,8]].
Thank you in advance!
+?ArrayListobjects. What other output would you expect?1 2 3 4 5 6 1 8on one single line