1

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}}

2
  • 3
    int[][] array = int[n][2]; ? You can then access, for example, array[1][0] Commented Mar 6, 2019 at 15:52
  • 1
    Integer[][]?? Commented Mar 6, 2019 at 15:52

2 Answers 2

1
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/

Sign up to request clarification or add additional context in comments.

Comments

1

You can use this I think.

final int n = 5;
Integer[][] ints = new Integer[n][2];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.