In Java, how can I print an array of ints?

Is there any built in method in order to do this?

When I try to print it I just get [I@1eed786

Is there an easy way of printing it?

~ I always give 10 pts for best answer!

5 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    reason for the odd result when printing an array directly is that is it printing the memory address of the array.

    in order to print all the values of an array is to iterate through all the values.

    for(int i = 0; i < someArray.Length; i++){

    system.out.println(someArray[i]);

    }

    • Login to reply the answers
  • 3 years ago

    Print An Array Java

    • Login to reply the answers
  • 6 years ago

    form Java 1.5 you can use:

    Arrays.toString(array)

    • Login to reply the answers
  • Anonymous
    5 years ago
    • Login to reply the answers
  • How do you think about the answers? You can sign in to vote the answer.
  • 1 decade ago

    You can always:

    import java.util.Arrays;

    ...

    int[] myArray = new myArray[10];

    System.out.println(

    Arrays.toString(myArray) );

    or do it with a for loop

    for( int i = 0; i< myArray.length; i++)

    System.out.println( myArray[i]);

    the System.out.println will automatically seek out the toString() method for the number(s)

    • Login to reply the answers
Still have questions? Get your answers by asking now.