Hi,
the parameters you passed into method m1(int[] i1, int[] i2) are local variables, so whatever they are doing inside the method m1, is not going to affect the original i1, i2 which are defined in the main method. That's what happens in the code1.
However, in code2, the elements of two arrays really swap; i1[0] becomes 3, i2[0] becomes 1, that's why output is 3,1
I hope above is clear for your question. I had the similar problem before too :-)