Values & References7 / 16
Up next

Value vs reference types

class Main {
    public static void main(String[] args) {
        // a primitive assignment copies the value
        int a = 5;
        int b = a;
        b++;
        System.out.println(a + " " + b);
        // an array is a reference: both names point at one object
        int[] x = {1, 2, 3};
        int[] y = x;
        y[0] = 99;
        System.out.println(x[0]);
    }
}
What you're solving

primitives copy; objects are shared