import java.util.Arrays;
public class ArrayDemo {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int temp[] = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 0 };// 声明一个无序数组 int point = Arrays.binarySearch(temp, 4);// 检索“4”在数组中的位置,若不排序,无法获得正确的位置 System.out.println("“4”在数组中的位置------" + point); Arrays.sort(temp);// 调用排序方法----->从小到大 System.out.print("排序后的数组"); System.out.println(Arrays.toString(temp));// 以字符串的形式输出数组 // 如果想使用二分法查询的话,必须是排序后的数组 int point1 = Arrays.binarySearch(temp, 4);// 检索“4”在数组中的位置 System.out.println("“4”在数组中的位置------" + point1); Arrays.fill(temp, 3);//填充数组---->将数组中的内容全部变为3 System.out.println("将数组中的内容全部变为3------" + Arrays.toString(temp)); }
}