0

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;
    }
}
3
  • You're not being very specific about the case.. How do you want to store a solution in an array? Commented May 19, 2015 at 12:40
  • 1
    The 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? Commented May 19, 2015 at 14:15
  • @CrazyGirl can you post the Array class code Commented May 19, 2015 at 14:18

1 Answer 1

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);
}
Sign up to request clarification or add additional context in comments.

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.