After Java code is run, the array printed is not the same as the array in the code

This is my .java file:

public class InsertionSort {
    public static void main (String[] args) {
        int hand[] = new int[] {1, 5, 2, 7, 3, 9, 8, 0};

    public static void sort (int[] hand) {

Now, when I do this command (I am using Vim so the command below compiles the code)

:!javac %

the InsertionSort.class file is created. I then open up terminal and do

java InsertionSort

it prints this:


How come it is so different from the actual array which I initialized in the code?

Source: java

Leave a Reply