- package com.kxg_04;
- import java.util.Arrays;
- public class ArrayDemo {
- public static void main(String[] args) {
- int[] arr = { 1, 22, 5, 645, 8, 9, 21, 35, 45 };
- // Arrays:针对数组进行操作的工具类,比如说排序和查找。
- // public static String toString (int[]a):数组转成字符串
- System.out.println(Arrays.toString(arr));
- // public static void sort(int []a ):对数组进行排序
- Arrays.sort(arr);
- System.out.println(Arrays.toString(arr));
- // public static int binarySearch(int [] a,int key):二分查找
- int i = Arrays.binarySearch(arr, 8);
- System.out.println(i);
- }
- }
复制代码
|
|