Arrays类详解
package Base;
import java.util.Arrays;
public class Demon01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Scanner scanner=new Scanner(System.in);
int[] a= {1,2,3,4,9090,12345,543,21,3,23};
System.out.println(a);//[I@15db9742
//打印数组元素
System.out.println(Arrays.toString(a));
printArray(a);
Arrays.parallelSort(a);//给数组排序
System.out.println(Arrays.toString(a));
}
public static void printArray(int[] a) {
for(int i=0;i<a.length;i++) {
if(i==0) {
System.out.print("[");
}
if(i==a.length-1) {
System.out.println(a[i]+"]");
}else {
System.out.print(a[i]+", ");
}
}
}
}
输出结果:
[I@15db9742
[1, 2, 3, 4, 9090, 12345, 543, 21, 3, 23]
[1, 2, 3, 4, 9090, 12345, 543, 21, 3, 23]
[1, 2, 3, 3, 4, 21, 23, 543, 9090, 12345]

浙公网安备 33010602011771号