/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.lab16_arrays2_calebfontenot;

import java.util.Arrays;

/**
 *
 * @author caleb
 */
public class ArrayCopy4 {

    public static void main(String[] args)
    {
        int[] array = {1, 2, 3, 4, 5};
        int[] array1 = Arrays.copyOfRange(array, 2, 5);
        int[] array2 = new int[array.length - 2];
        int[] array3 = new int[array.length];
           System.out.println("array1: (copy with java.util.Arrays.copyOfRange(); )");
        for (int i: array1) {
            System.out.print(i + " ");
        }
        System.out.println();
        // Copy array into array2 with a for loop and print it
        System.out.println("array2: (copy with System.arraycopy(); )");
        System.arraycopy(array, 2, array2, 0, 3);
        for (int i : array2) {
            System.out.print(i + " ");
        }
        System.out.println();
        // Copy array manually
        System.out.println("array3: (manually copy with for loop)");
        for (int i : array3) {
            array[i] = array3[i];
        }
        for (int i : array1) {
            System.out.print(i + " ");
        }
        System.out.println();
    }
}
