数组复制
语法:System.arraycopy(源数组名称,源数组复制开始索引,目标数组名,目标数组复制开始索引,长度);
数组A:1,2,3,4,5,6,7,8;
数组B:11,22,33,44,55,66,77,88;
将数组A的部分内容替换到数组B中,数组B的最终结果为:11,22,33,5,6,7,77,88;
package shuzufuzhi;
import java.security.PublicKey;
import java.sql.SQLOutput;
/**
-
@Author: Lenovo
-
@CreateTime: 2018-12-19 14:19
*/
//数组A:1,2,3,4,5,6,7,8;
// 数组B:11,22,33,44,55,66,77,88;
// 将数组A的部分内容替换到数组B中,数组B的最终结果为:11,22,33,5,6,7,77,88;
public class FuZhi {
public static void main(String[] args) {
int[] A=new int[]{1,2,3,4,5,6,7,8};
int[] B=new int[]{11,22,33,44,55,66,77,88};
System.arraycopy(A,4,B,3,3);//数组复制
daYin(B);}
public static void daYin(int[] temp){
for(int i=0;i<temp.length;i++){
System.out.print(temp[i]+",");
}
System.out.println();
}
}
数组排序
语法:java.util.Arrays.sort(数组名称);
数组A:{3,5,9,8,7,6};
从小到大排列已知数组
package shuzufuzhi;
/**
-
@Author: Lenovo
-
@CreateTime: 2018-12-19 15:34
*/
//数组A:{3,5,9,8,7,6};
// 从小到大排列已知数组
public class ShuZu {
public static void main(String[] args) {
int[] A=new int[]{3,5,9,8,7,6};
java.util.Arrays.sort(A);//数组排序
daYin(A);
}public static void daYin(int[] temp) {
for (int i = 0; i < temp.length; i++) {
System.out.print(temp[i] + “,”);
}
System.out.println();
}
}
利用这些方法可以快速完成工作任务,
面试的时候不适用!