Java 之 Arrays 类
一、概述 java.util.Arrays 此类包含用来操作数组的各种方法。比如排序和搜索等,其所有方法均为静态方法,调用非常方便。 二、操作数组的方法 public static Sting toString(int[ ] a):返回指定数组内容的字符串表示形式 public static void sort(int[ ] a):对指定的 int 型数组按数字升序进行排序。 Demo1: 1 public static void main(String[] args) { 2 // 定义int 数组 3 int[] arr = {2,34,35,4,657,8,69,9}; 4 // 打印数组,输出地址值 5 System.out.println(arr); // [I@2ac1fdc4 6 // 数组内容转为字符串 7 String s = Arrays.toString(arr); 8 // 打印字符串,输出内容 9 System.out.println(s); // [2, 34, 35, 4, 657, 8, 69, 9] 10 } Demo2: 1 public static void main(String[] args) { 2 // 定义int 数组 3 int[] arr = {24, 7, 5, 48, 4, 46, 35, 11, 6, 2