/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayCopy4.java |
package com.calebfontenot.lab16_arrays2_calebfontenot;
import java.util.Arrays;
@author
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();
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();
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();
}
}