Java数组05——Arrays类
package array;
import java.util.Arrays;
public class ArrayDemon07 {
public static void main(String[] args) {
int[] a={1,3,2,5,4,10000};
//System.out.println(a);//[I@1b6d3586
//打印数组元素
//System.out.println(Arrays.toString(a)); //[1, 3, 2, 5, 4, 10000]
//printArray(a);
Arrays.sort(a);// 对数组进行排序:升序
System.out.println(Arrays.toString(a));// [1, 2, 3, 4, 5, 10000]
//数组填充
Arrays.fill(a,0);
System.out.println(Arrays.toString(a));// [0, 0, 0, 0, 0, 0]
Arrays.fill(a,2,4,10000);//第二到第四个元素之间填充
System.out.println(Arrays.toString(a));//[0, 0, 10000, 10000, 0, 0]
}
// 重复造轮子 [1,3,2,5,4,10000]
public static void printArray(int array[]){
for (int i = 0; i <array.length ; i++) {
if (i==0){
System.out.print("[");
}
if (i==array.length-1){
System.out.print(array[i]+"]");
}else{
System.out.print(array[i]+", ");
}
}
}
}