Home > Java > javaTutorial > How to copy an array in java

How to copy an array in java

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-04-29 22:22:17
forward
1479 people have browsed it

Copy of array

First type:

  把一个数组的值拷贝到另一个数组
 public static int[] copyArray(int[] array){
        int[] copy = new int[array.length];
        for (int i = 0; i <array.length ; i++) {
            copy[i] = array[i];
        }
        return copy;
    }
 
    public static void main(String[] args) {
        int[] array = {1,4,6,3,8,9};
        int[] ret = copyArray(array);
        System.out.println(Arrays.toString(ret));
 
 
    }
Copy after login

Print result:

How to copy an array in java

Second type:

Copy array (self) function

How to copy an array in java

Print result:

How to copy an array in java

The length can also be multiplied by 2, but not in the original On the basis of expanding 2 times, here is a new object

How to copy an array in java

Copy array (part) function:

How to copy an array in java

All source codes in Java from and to are left-closed and right-open.

The third type:

How to copy an array in java

Print result:

How to copy an array in java

The fourth copy:

How to copy an array in java

The above is the detailed content of How to copy an array in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template