1

Here is the source code

class App {
public static void main(String[] args){

    int[] x = {0,1,2,3,4,5,6,7,8,9};
    int[] xcopy = java.util.Arrays.copyOfRange(x,0,3);

    System.out.println(xcopy);
}
}

The code compiles without error, but the result is this:

[I@659e0bfd

when it should be:

0,1,2

Why isn't this working? or more interestingly, where did the initial result come from?

1
  • Hint: this is nothing to do with copyOfRange. System.out.println(x) would do the same thing. As would System.out.println(new int[] {1, 2, 3});. Commented Mar 24, 2015 at 2:33

1 Answer 1

0

You are trying to print out an array. You should be using a loop to iterate through the array and print out each individual int

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

1 Comment

or there is a method Arrays.toString(myArray) to achieve this

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.