Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int[] origNum = { 1, 2, 3 };
        String[] origNames = { "Java", "SQL" };
        System.out.println("Before method  call, origNum:" + Arrays.toString(origNum));
        System.out.println("Before method  call, origNames:" + Arrays.toString(origNames));

        // Call methods passing the arrays 
        tryElementChange(origNum);
        tryElementChange(origNames);

        System.out.println("After method  call, origNum:" + Arrays.toString(origNum));
        System.out.println("After method  call, origNames:" + Arrays.toString(origNames));
    }

    public static void tryElementChange(int[] num) {
        if (num != null && num.length > 0) {
            num[0] = -1;
        }
    }

    public static void tryElementChange(String[] names) {
        if (names != null && names.length > 0) {
            names[0] = "T";
        }
    }
}