数组代码

public class CH04_1 {
public static void main(String[] args) {
//比较两个数组是否相等
int [] num1 = {1,2,3,4,5};
int num2 [] = {1,2,3,4,5};
boolean eq = Arrays.equals(num1,num2);
System.out.println(eq);
//数组排序
int [] num3 = {12,34,23,454,67,89,16,56};
Arrays.sort(num3);
System.out.println(Arrays.toString(num3));
//fill
int [] num4 = {1,2,3,4,4,5,5,5,67};
Arrays.fill(num4,0);
System.out.println(Arrays.toString(num4));
//copyOf
int [] num5 = {1,2,3,4,5,6,7,8};
int [] tep = Arrays.copyOf(num5, 4);
System.out.println(Arrays.toString(tep));
//binarySearch
int [] num6 = {12,34,23,454,67,89,16,56};
Arrays.sort(num6);
System.out.println(Arrays.binarySearch(num6, 89));
}
}

posted @ 2016-11-03 13:56  造西  阅读(169)  评论(0编辑  收藏  举报