import java.util.*;
public class BinarySe{
public static void main(String args[]){
int array1 [] = new int []{12,23,34,45};
int array2 [] = new int []{12,23,34,45};
int index = Arrays.binarySearch(array1,45);
System.out.println(index);
System.out.println("变换之前:array1="+array1);
//[1]copyOf()方法
array1=Arrays.copyOf(array1,10);//如果变换之后的数组比原来的数组长度长,则以0进行补全
System.out.println("变换之后:array1="+array1);//第一次数组的内存地址
for(int i:array1){
System.out.print(i+"\t");
}
System.out.println();
array1=Arrays.copyOf(array1,2);//第二次数组的内存地址
//实际上,这两次的数组的内存地址是不相同的,因为数组一旦定义,声明,内存地址是不可以变化大的
System.out.println("变换之后:array1="+array1);//如果变换之后,数组的长度比原来的数组的长度小,则自动进行截取
for(int i:array1){
System.out.print(i+"\t");
}
System.out.println();
System.out.println("\tarray1==array2"+(array1==array2));
//[2]equals()方法
System.out.println("Arrays.equals(array1,array2)"+(Arrays.equals(array1,array2)));
Arrays.fill(array1,88);
for(int i:array1){
System.out.print(i+"\t");
}
//[3]sort()方法
String [] str1 = {"张三","李四","王五","赵六","马七"};
String str2 [] = new String[] {"zoo","banana","apple","peach","reap"};
Arrays.sort(str1);
for(String i:str1){
System.out.print(i+"\t");
}
System.out.println();
Arrays.sort(str2);
for(String i:str2){
System.out.print(i+"\t");
}
}
}