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) {

        // intializing an array arr1
        int[] arr1 = new int[] { 1, 2, 3 };

        System.out.println(Arrays.toString(arr1));

        // copying array arr1 to arr2 with newlength as 5
        int[] arr2 = Arrays.copyOf(arr1, 5);
        arr2[3] = 4;
        arr2[4] = 5;

        System.out.println(Arrays.toString(arr2));
    }
}