×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Fett 17
Added: Dec 5, 2021 11:04 AM
Views: 783
Tags: no tags
  1. // initializing an array original
  2.         int[] org = new int[] {1, 2 ,3};
  3.  
  4.         System.out.println("Original Array");
  5.         for (int i = 0; i < org.length; i++)
  6.             System.out.print(org[i] + " ");
  7.  
  8.         // copying array org to copy
  9.         int[] copy = Arrays.copyOf(org, 5);
  10.  
  11.         // Changing some elements of copy
  12.         copy[3] = 11;
  13.         copy[4] = 55;
  14.  
  15.         System.out.println("\nNew array copy after modifications:");
  16.         for (int i = 0; i < copy.length; i++)
  17.             System.out.print(copy[i] + " ");