This is my array:  int[] test= new int[] {1,0,1,0,0,0,0,0,0,0}
Now I need to remove all the zeros from this array so it will display like this: Output : {1,1}
I tried this code from this link-StackOverFlow but didn't work for me.
    int j = 0;
    for (int i = 0; i < test.length; i++) {
        if (test[i] != 0)
            test[j++] = test[i];
    }
    int[] newArray = new int[j];
    System.arraycopy(test, 0, newArray, 0, j);
    return newArray;
Please help me to solve this.