【ThinkingInJava】45、用java标准库里面的静态函数调用,复制数组

本文介绍了如何利用Java标准库中的静态函数实现数组复制,并通过示例代码展示了具体操作过程。
/**
* 书本:《Thinking In Java》
* 功能:用java标准库里面的静态函数调用,复制数组
* 文件:CopyingArrays.java
* 时间:2015年4月30日07:42:44
* 作者:cutter_point
*/
package Lesson16Arrays;

import static net.mindview.util.Print.*;

import java.util.Arrays;

public class CopyingArrays
{

	public static void main(String[] args)
	{
		int[] i = new int[7];
		int[] j = new int[10];
		//吧这两个数组分别填充为47和99
		Arrays.fill(i, 47);
		Arrays.fill(j, 99);
		//输出这两个
		print("i = " + Arrays.toString(i));
		print("j = " + Arrays.toString(j));
		//复制数组,参数分别是
//		* @param      src      the source array.
//	     * @param      srcPos   starting position in the source array.
//	     * @param      dest     the destination array.
//	     * @param      destPos  starting position in the destination data.
//	     * @param      length   the number of array elements to be copied.
		System.arraycopy(i, 0, j, 0, i.length);
	}

}


输出:

i = [47, 47, 47, 47, 47, 47, 47]  obj1
j = [99, 99, 99, 99, 99, 99, 99, 99, 99, 99]  obj1





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值