Reputation: 37
I have been trying to make an array of integer arrays. I know that the outer array will have length N whilst every integer array within in only needs to hold two values.
Originally, I made an ArrayList with an Integer array:
int[] intArray = new int[2];
ArrayList<IntArray> outerArray = new ArrayList<>();
I then proceeded to just make an ArrayList of Integer within another ArrayList:
ArrayList<ArrayList<Integer>> outerArray = new ArrayList<>();
I'm looking for something that looks like this if N = 3 and a,b,c are integers:
{{a1, a2}, {b1, b2}, {c1, c2}}
Upvotes: 1
Views: 8304
Reputation: 11
You can use this I think.
final int n = 5;
Integer[][] ints = new Integer[n][2];
Upvotes: 1
Reputation: 92
private int[][] array = new int[10][10];
And you wrote something like this :
ArrayList<ArrayList<Integer>>
This is not an array, but list. You might read this : https://www.geeksforgeeks.org/array-vs-arraylist-in-java/
Upvotes: 1