//*******************************************************************************
// Array elements: Are they a copy of, or reference to the original?                          
//*******************************************************************************
import java.util.Arrays;

public class array4   
{
    public static void main(String[] args)
    {
        System.out.println("Array of integers...");
        int[] nums = new int[10];
        int num1 = 1;
        int num2 = 2;
        int num3 = 3;
        nums[0] = num1;
        nums[1] = num2;
        nums[2] = num3;
        System.out.println(Arrays.toString(nums));
        num1 += 10;
        System.out.println("Variable num1 has been changed to: " + num1);
        System.out.println(Arrays.toString(nums));                 //element in array not affected
        System.out.println();


        System.out.println("Array of Strings...");
        String[] names = new String[10];
        String a = "Sam";
        String b = "John";
        String c = "Bill";
        names[0] = a;
        names[1] = b;
        names[2] = c;
        System.out.println(Arrays.toString(names));
        a += " Sultan";
        System.out.println("Variable a has been changed to: " + a);
        System.out.println(Arrays.toString(names));                 //element in array not affected
        System.out.println();										//Strings are immutable, when 'a' was changed, you get a diff. String


        System.out.println("Array of StringBuffers...");
        StringBuffer[] names2 = new StringBuffer[10];
        StringBuffer x = new StringBuffer("Sam");
        StringBuffer y = new StringBuffer("John");
        StringBuffer z = new StringBuffer("Bill");
        names2[0] = x;
        names2[1] = y;
        names2[2] = z;
        System.out.println(Arrays.toString(names2));
        x.append(" Sultan");
        System.out.println("Variable x has been changed to: " + x);
        System.out.println(Arrays.toString(names2));                //element in array has changed
    }
}