
Explanation of Solution
Examples of assigning existing array entries to new array variable:
First Example:
One method to assign the existing array entries to new array variable is clone() method.
Let us consider the existing array entries is,
int[] original = {1, 2, 3, 4, 5};
The new array variable is,
int[] backup;
Need to make copy of existing array entries of “original” and provide a reference to new array variable “backup” by using clone() method is given below:
backup = original.clone();
The clone() method initialize each and every cell of new array to value that stored in the corresponding cell of existing array “original”.
Thus, it copies all int array entries from “original” to “backup”.
Second example:
Another method to copy the existing array entries to new array is java.util.Arrays.copyOf() method.
Let us consider the existing array entries is,
int[] original = {1, 2, 3, 4, 5};
The new array variable is,
int[] backup;
Need to make copy of existing array entries of “original” and provide a reference to new array variable “backup” by using java.util.Arrays.copyOf() method is given below:
backup = java...

Want to see the full answer?
Check out a sample textbook solution
Chapter 3 Solutions
Data Structures and Algorithms in Java
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage Learning




