Java Program to copy elements of one array into another array
CopyArray.java
/* Code From Learnoset - Learn Coding Online.
Download Learnoset App from PlayStore to learn coding,
projects, algorithms, error handling
*/
// Java Program to copy elements of one array into another array
public class CopyArray {
public static void main(String[] args) {
//Initialize array
int[] arr1 = {1, 2, 3, 4, 5, 6, 7, 8};
/* declare new array variable.
we are copying every element of 'arr1' so we used
'arr1.length' into 'arr2'*/
int[] arr2 = new int[arr1.length];
//Copying all elements of 'arr1' into 'arr2'
for (int i = 0; i < arr1.length; i++) {
arr2[i] = arr1[i];
}
//Displaying elements of 'arr1'
System.out.println("Elements of original array: ");
for (int i = 0; i < arr1.length; i++) {
System.out.print(arr1[i] + " ");
}
System.out.println();
//Displaying elements of 'arr2'
System.out.println("Elements of new array: ");
for (int i = 0; i < arr2.length; i++) {
System.out.print(arr2[i] + " ");
}
}
}
Projects with Source Code + Video Tutorials
You can download our Java and Android Studio Projects with Source Code and Video Tutorials.
![How-to-create-Modern-Login-and-Register-screen-in-Android-Studio-|-Material-UI-Design-|-Part---06](https://learnoset.com/Learnoset/Projects/LoginRegister06/thumbnail.jpg)
How to create Modern Login and Register screen in Android Studio | Material UI Design | Part - 06
![TicTacToe-Game-For-Android-(Offline-Version).](https://learnoset.com/Learnoset/Projects/TicTacToe/thumnail2.jpg)
TicTacToe Game For Android (Offline Version).
![Login-and-Register-using-Firebase-Realtime-Database](https://learnoset.com/Learnoset/Projects/LoginRegisterFirebase/thumbnail.jpg)
Login and Register using Firebase Realtime Database
If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com
Follow us to learn Coding and get in touch with new Technologies.