1,length; 返回数组长度
2,Arrays.sort();数组排序
3,Arrays.toString(a)一维数组转化为字符串
4,Arrays.sort(b,(x,y)->{return x[0]-y[0];});二维数组排序
5,deepToString(b) 二维数组转化为字符串
6,Arrays.fill(c,-1); 初始化一维数组
代码实现
import java.util.Scanner;
import java.util.Arrays;
public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);int n = sc.nextInt();int[] a = new int[n+1];for(int i=1;i<=n;i++){a[i] = sc.nextInt();}//1,length; 返回数组长度System.out.println(a.length);//2,Arrays.sort();数组排序Arrays.sort(a);for(int i=1;i<=n;i++){System.out.printf("%d ",a[i]);}System.out.println();//一维数组转化为字符串System.out.println(Arrays.toString(a));//3,二维数组排序int[][] b = {{5,2,3,4},{9,6,7,8,},{1,10,11,12}};//按照第i个位置的数的大小排序Arrays.sort(b,(x,y)->{return x[0]-y[0];});for(int[] h:b){for(int x:h){System.out.printf("%d ",x);}System.out.println();}//二维数组转化为字符串System.out.println(Arrays.deepToString(b));//4,初始化一维数组int [] c = new int[10];Arrays.fill(c,-1);for(int x:c)System.out.printf("%d ",x);//5,}
}