You can try using System.arraycopy()

int[] src  = new int[]{1,2,3,4,5};
int[] dest = new int[5];

System.arraycopy( src, 0, dest, 0, src.length );

But, probably better to use array.clone() in most cases:

int[] src = ...
int[] dest = src.clone();
Answer from Bala R on Stack Overflow
🌐
IIT Kanpur
iitk.ac.in › esc101 › 05Aug › tutorial › java › data › copyingarrays.html
Copying Arrays
Recall that array indices start at 0, so that the copy begins at the array element 'c'. The arraycopy method call puts the copied elements into the destination array beginning at the first element (element 0) in the destination array copyTo.
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-copy-in-java
Array Copy in Java - GeeksforGeeks
July 23, 2025 - This program shows that cloning a multi-dimensional array creates a shallow copy—the top-level array is duplicated, but inner arrays are still shared references. We can also use System.arraycopy() Method. The system is present in java.lang package.
🌐
Emory
cs.emory.edu › ~cheung › Courses › 170 › Syllabus › 09 › copy-array.html
Copying an array and changing the size of an array
Complete Java example: Output of this program: Conclusion: array b is a · independent and a true copy of the · array b. Example Program: (Demo above code) &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp · Prog file: click here ·
🌐
DataCamp
datacamp.com › doc › java › copyof
Java Array copyOf()
In this example, Arrays.copyOf() is used to create an exact copy of originalArray. The new array copiedArray contains all elements from the original array. import java.util.Arrays; public class CopyOfLargerExample { public static void main(String[] args) { int[] originalArray = {1, 2, 3}; int[] extendedArray = Arrays.copyOf(originalArray, 5); System.out.println("Extended Array: " + Arrays.toString(extendedArray)); } }
🌐
Scaler
scaler.com › home › topics › array copy in java
Array Copy in Java - Scaler Topics
December 27, 2023 - Copying one element at a time while iterating through every element of the original array provided. Using this method ensures that any changes to b won't affect the initial array a, as seen in the example below follows this example we, are going to check how to copy an array in java using for loop
🌐
Baeldung
baeldung.com › home › java › java array › how to copy an array in java
How to Copy an Array in Java | Baeldung
May 11, 2024 - In this quick tutorial, we’ll discuss the different array copying methods in Java. Array copying may seem like a trivial task, but it can cause unexpected results and program behaviors if not done carefully.
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › java › lang › system_arraycopy.htm
Java System arraycopy() Method
The Java System arraycopy() method copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array. A subsequence of array components are copied from the source array
🌐
DEV Community
dev.to › luthfisauqi17 › multiple-ways-to-copy-array-in-java-effectively-4lpj
Multiple Ways to Copy Array in Java Effectively - DEV Community
September 17, 2022 - As Output 4 shows, array b will not change if there is an update to any of the values in array a. Congratulations, you have successfully copied the value of array a to array b! But we will not stop here, because it turns out that Java has made it easy to copy array values to other arrays without having to use the iterative method.
🌐
TutorialsPoint
tutorialspoint.com › array-copy-in-java
Array Copy in Java
September 13, 2023 - public class Tester { public static void main(String args[]) { //Scenario 1: Copy array using assignment int[] a = {1, 2, 3}; int[] b = a; //test side effect b[0]++; System.out.println("Scenario 1: "); System.out.print("Array a: "); printArray(a); System.out.print("Array b: "); printArray(b); //Scenario 2: Copy array by iterating int[] c = {1, 2, 3}; int[] d = new int[c.length]; for (int i = 0; i < d.length; i++) { d[i] = c[i]; } //test side effect d[0]++; System.out.println("Scenario 2: "); System.out.print("Array c: "); printArray(c); System.out.print("Array d: "); printArray(d); //Scenario
🌐
Educative
educative.io › answers › how-to-copy-an-array-in-java
How to copy an array in Java
Here are some alternative ways to do a shallow copy… · The System.arraycopy method can be used to copy an array or a sub-array:
🌐
Baeldung
baeldung.com › home › java › java array › performance of system.arraycopy() vs. arrays.copyof()
Performance of System.arraycopy() vs. Arrays.copyOf() | Baeldung
January 8, 2024 - When estimating the performance of System.arraycopy(), we need to keep in mind that it is a native method. Native methods are implemented in platform-dependent code (typically C) and accessed through JNI calls. Because native methods are already compiled for a specific architecture, we can’t precisely estimate the runtime complexity. Moreover, their complexities can differ between platforms. We can be sure that the worst-case scenario is O(N). However, the processor can copy contiguous blocks of memory one block at a time (memcpy() in C), so actual results can be better.
🌐
Coding Shuttle
codingshuttle.com › home › handbooks › java programming handbook › java copy arrays
Java Copy Arrays | Coding Shuttle
April 9, 2025 - This is useful when we want to create a duplicate of an existing array without modifying the original one. ... The most basic way to copy an array is to use a loop.
🌐
Quora
quora.com › How-do-I-copy-one-array-to-another
How to copy one array to another - Quora
In Java, you have the flexibility to copy arrays through two distinct approaches: utilizing the direct copy method from java.util package or employing the System class.
🌐
Tutorjoes
tutorjoes.in › Java_example_programs › copy_the_elements_of_one_array_into_another_array_in_java
Write a program to copy the elements of one array into another array
import java.util.Scanner; class Array_Copy { public static void main(String[] args) { Scanner input =new Scanner(System.in); System.out.print("Enter the Array Limit :"); int l =input.nextInt(); int [] a =new int[l]; int [] c =new int[l]; int sum = 0; for(int i=0;i<l;i++) { System.out.printf("Element of a[%d] :",i); a[i]=input.nextInt(); } for(int i=0;i<l;i++) { c[i] = a[i]; } System.out.print("\nOriginal Array Elements..."); for(int i=0;i<l;i++) { System.out.printf("\na[%d] = %d",i,a[i]); } System.out.print("\n\nCopy Array Elements one to Another Array..."); for(int i=0;i<l;i++) { System.out.printf("\nc[%d] = %d",i,c[i]); } } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › arrays-copyof-in-java-with-examples
Arrays copyOf() in Java with Examples - GeeksforGeeks
July 23, 2025 - Cheatsheet · DSA in Java · Java Collection · Last Updated : 23 Jul, 2025 · Arrays.copyOf() is a method of java.util.Arrays class. It is used to copy the specified array, truncating or padding with false (for boolean arrays) if necessary ...
🌐
Career Karma
careerkarma.com › blog › java › 4 ways to copy an array in java
4 Ways to Copy an Array in Java: The Complete Guide | Career Karma
December 1, 2023 - This needs to be a deep copy because we plan on changing the contents of the summer_coffees array to reflect the new coffees we will offer in the summer months. Here’s the code we would use to create a deep copy using a for loop: import java.util.Arrays; class LoopCopy { public static void main(String[] args) { String[] coffees = {"Espresso", "Mocha", "Latte", "Cappuccino", "Pour Over", "Flat White"}; String[] summer_coffees = new String[6]; for (int i = 0; i < coffees.length; ++i) { summer_coffees[i] = coffees[i]; } System.out.println(Arrays.toString(summer_coffees)); } }
🌐
CodeGym
codegym.cc › java blog › java arrays › java system.arraycopy() method
Java System.arraycopy() Method
January 7, 2025 - The arraycopy method copies data from src, starting from srcIndex till srcIndex +(len - 1) elements, to the dest array at destIndex till destIndex + (len - 1). The arraycopy method is has a void return type which means it does not return anything. ...
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java copy array: how to copy / clone an array in java
Java Copy Array: How To Copy / Clone An Array In Java
April 1, 2025 - Here we have modified the previous program to include for loop and inside for loop, we assign each element of intArray to the corresponding element of copyArray. This way, the elements are actually copied. So when one array is modified, the changes do not reflect in another array. Java’s System class has a method called “ArrayCOpy” that allows you to copy elements of one array to another array.