Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
Expert Solution & Answer
Book Icon
Chapter 3, Problem 14R

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...

Blurred answer
Students have asked these similar questions
Write a Java program with the following: A constructor to assign values to the variable and the array. All values should be enteredby the user through the keyboard.
Java Can an entire array be passed as a parameter? How is this accomplished?  How is an array of objects created?
This is needed in Java   Given that an ArrayList of Strings  named nameList has already been created and names have already been inserted, write the statement necessary to delete the name at index 15.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education