System和Arrays类常用方法

System.java

public static native void arraycopy(Object src,  int  srcPos, Object dest, int destPos, int length);
/**
Copies an array from the specified source array, beginning at the specified position, to the specified position of 
the destination array. A subsequence of array components are copied from the source array referenced by src to 
the destination array referenced by dest. The number of components copied is equal to the length argument. 
The components at positions srcPos through srcPos+length-1 in the source array 
are copied into positions destPos through destPos+length-1, respectively, of the destination array.
将源数组src的下标为srcPos开始的length个元素,移到目标数组dest的下标destPos位置
 */

注意:把数组src的元素复制到数组dest,这里是浅复制,不是深复制,即只是数组src元素的对象引用复制到数组dest。


Arrays.java

public static void sort(int[] a, int fromIndex, int toIndex)
/**
* short,char,byte,double,float,long
*/


public static void sort(Object[] a, int fromIndex, int toIndex)
/**
* short,char,byte,int,double,float,long
*/


public static int binarySearch(int[] a, int fromIndex, int toIndex, int key)
/**
* short,char,byte,double,float,long
*/


public static void fill(Object[] a, int fromIndex, int toIndex, Object val)

public static void fill(Object[] a, int fromIndex, int toIndex, Object val) {
        rangeCheck(a.length, fromIndex, toIndex);
        for (int i=fromIndex; i<toIndex; i++)
            a[i] = val;
    }
注意:调用此方法,则数组a里的每个元素值都是val,如果val不是基本类型,而是对象类型,那么数组a的元素初始化值是对象val的引用,或换种说法,数组元素指向的都是同一个对象,一旦改变某个数组对象的属性,则数组其他元素也会改变,因为数组里的元素保存都是同一个对象引用。


public static int[] copyOfRange(int[] original, int from, int to)
/**
* short,char,byte,double,float,long
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值