Skip to content

Instantly share code, notes, and snippets.

@charlesreid1
Created March 2, 2017 15:22
Show Gist options
  • Save charlesreid1/5066680b31f4c10fdcbf1d316a07b162 to your computer and use it in GitHub Desktop.
Save charlesreid1/5066680b31f4c10fdcbf1d316a07b162 to your computer and use it in GitHub Desktop.
import java.util.*;
public class ArraysInPlace {
public static void main(String[] args) {
int x = 5;
System.out.println(x);
proofThatWeCopy(x);
System.out.println(x);
int[] y = new int[3];
y[0] = 100;
y[1] = 200;
y[2] = 300;
System.out.println(Arrays.toString(y));
noWeDont(y);
System.out.println(Arrays.toString(y));
}
public static void proofThatWeCopy(int x) {
x = 100;
}
public static void noWeDont(int[] y) {
y[0] = 77777;
y[1] = 88888;
y[2] = 99999;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment