0

This generates the array.

public word (String file)
{...
    public int[] getArray()
    {       
       int[] array = {... } ;
       return array;
       }
}

And I need to reference that array in another class

public static void main()
{
    word numarray = new word("doc.txt");
    int [] heightarray =  numarray.getArray();
    System.out.println(heightarray);
}

I'm not getting any errors but I get things like [I@1a6fa30c as a result.

1
  • If you want to print it, use heightarray.toString() Commented May 7, 2014 at 1:56

2 Answers 2

2

What you are getting in the output is the hashcode of the array. In order to print the contents of the array you can you either of the below options :

Option 1 : Print the elements one by one using a loop a below :

for(int val : heightarray)
{
   System.out.print(val + ",");
}

Option 2 : Use Arrays utility class for printing the array

System.out.println(Arrays.toString(heightarray));
Sign up to request clarification or add additional context in comments.

Comments

2

You can print it using the Arrays.toString() method:

System.out.println(Arrays.toString(heightarray));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.