java-Arrays类

package com.day9.Array;

import java.util.Arrays;

public class Demo1Arrays {

  /**
  * public static String toString(int[] a),返回数组指定的字符串形式
  * public static void sort(int[] a),排序
  * public static int binarySearch(int[] a,int key)二分查找
  */
  public static void main(String[] args) {
    int[] arr={1,2,3,4,5,6,7,10,9,8};
    System.out.println(Arrays.toString(arr));//[1,2,3,4,5,6,7,10,9,8]

    Arrays.sort(arr);
    System.out.println(Arrays.toString(arr));//[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    int[] arr1={1,2,3,4,5,6,7,8};
    System.out.println(Arrays.binarySearch(arr1,6));//5
    System.out.println(Arrays.binarySearch(arr1,60));//-9(-的插入点-1即-8-1=-9)
  }

}

posted @ 2017-12-28 22:00  简简单单zjl  阅读(134)  评论(0编辑  收藏  举报