java 复制数组

import java.util.*;

public class copyArray {
    public static void main(String[] args) {
        int[] e = {4,5,2,7,8};
        int[] f;
        f = Arrays.copyOf(e,3);// input 0-2
        for (int k = 0; k < f.length; k++) {
            System.out.print(f[k]+" ");
        }
        System.out.println();

        int[] a = {1, 2, 3, 4};
        int[] b = new int[10];
        b = Arrays.copyOfRange(a, 0, 4);
        for(int i = 0; i < 4; i++)
            System.out.print(b[i]+" ");
        System.out.println();


        int[] c = {4,5,2,7,8};
        int[] d;
        d = c.clone();
        for (int j = 0; j < d.length; j++) {
            System.out.print(d[j]+" ");
        }
        System.out.println();

        int[] g = {4,8,6,3,4,56};
        int[] h = new int[10];
        System.arraycopy(g,2,h,3,4);//A starts from 2 and copies from 0-3 to B starts from 3
        for (int n = 0; n < h.length; n++) {            //a从2开始往后0-3复制到b从3开始放入
            System.out.print(h[n]+" ");
        }

    }
}

输出结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

开心比较堵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值