Java的Arrays

asList(T... a)

List message = Arrays.asList("AA", "BB", "CC");
        for (String ms : message) {
            System.out.print(ms+"\t");
        }

binarySearch(折半查询)

//有序
        int[] a = { 1, 2, 3, 4, 5, 6 };
        int index = Arrays.binarySearch(a, 0, 3, 2);
        System.out.print(index);

copyOf(扩容)

int[] b = Arrays.copyOf(a, a.length + 10);
        for (int i = 0; i < b.length; i++) {
            System.out.print(b[i] + "\t");
        }

copyOfRange(复制指定范围的数组)

int[] c = Arrays.copyOfRange(a, 0, 3);
        for (int i = 0; i < c.length; i++) {
            System.out.print(c[i] + "\t");
        }

equals(比较两个数组的元素是否相同)

int[] d = Arrays.copyOf(c, c.length);
System.out.println(Arrays.equals(c, d));

fill(将指定的int值分配给指定的int数组的每个元素)

        System.out.println(Arrays.toString(d));
        Arrays.fill(d, 1);
        System.out.println(Arrays.toString(d));

sort (按升序排列数组的指定范围)

        int[] e = { 233, 45, 67, 32 };
        Arrays.sort(e, 0, 3);//排不到3
        System.out.println(Arrays.toString(e));

toString(返回指定数组的内容的字符串表示形式)

int[] f= {1,2,3,4};
        System.out.println(Arrays.toString(f));

你可能感兴趣的:(Java的Arrays)