I am printing an array of arraylist which contains 2d array.
ArrayList<ArrayList<ArrayList<Array>>> sols;
I am trying to print this:
System.out.print(sols.get(0).get(0).get(0));
was expecting a 2d array as it was the lowest level of the variable
I get this instead
app.Array@42037252
How can I print the specified 2d array?
EDIT
this is my Array class
public class Array {
int[][] array;
public Array(int[][] initialArray){
array = initialArray;
}
}
-
You're not being very specific about the case.. How do you want to store a solution in an array?moffeltje– moffeltje2015年05月19日 12:40:38 +00:00Commented May 19, 2015 at 12:40
-
1The class app.Array does not implement toString() so the default Object's toString is being called and "class@hexhashcode" is being printed. Did you write the "Array" class?FriedSaucePots– FriedSaucePots2015年05月19日 14:15:19 +00:00Commented May 19, 2015 at 14:15
-
@CrazyGirl can you post the Array class codeashosborne1– ashosborne12015年05月19日 14:18:20 +00:00Commented May 19, 2015 at 14:18
1 Answer 1
The string you are getting is the default representation of your Array object provided by Object.toString() method.
I suppose app.Array is a custom class implemented by you.
So to print out your 2d array in a more intuitive way you need to override the toString() method in your class.
For example:
@Override
public String toString(){
return Arrays.deepToString(array);
}