Java Arrays類
阿新 • • 發佈:2017-05-20
ear package str log sort ray cnblogs [] string
1 package demo04; 2 3 import java.util.Arrays; 4 5 public class ArraysDemo { 6 public static void main(String[] args) { 7 8 //static void sort(任意類型數組) 對數組升序排列 9 int[] arr = {5,1,2,6,3}; 10 Arrays.sort(arr); 11 for (int i = 0; i < arr.length; i++) {12 System.out.println(arr[i]); 13 } 14 15 //static int binarySearch(數組, 被查找的有序數組) 二分查找 返回負數(-插入點-1) 16 int[] arr1 = {1,2,3,4,5,6}; 17 int index = Arrays.binarySearch(arr1, 3); 18 System.out.println(index); 19 20 //static String toString(數組) 將數組轉為字符串21 int[] arr2 = {1,2,3,4,5,6}; 22 String s = Arrays.toString(arr2); 23 System.out.println(s); 24 25 } 26 }
Java Arrays類