其他分享
首页 > 其他分享> > Arrays类

Arrays类

作者:互联网

package array;

import java.util.Arrays;

public class ArrayDemo06 {
public static void main(String[] args) {

    int[] a = {13,567456,545,6546,4896465,6484,486};

    System.out.println(a);  //[I@16b98e56
    //打印数组元素        Arrays.toString()
    System.out.println(Arrays.toString(a));
    printArray(a);

    //数组进行排序:升序    Arrays.sort()
    Arrays.sort(a);
    printArray(a);

    //数组填充
    Arrays.fill(a,2,4,0);   //二到四的元素填充为0  左开右闭
    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]+", ");
    }
}

}

标签:printArray,Arrays,System,int,println,out
来源: https://www.cnblogs.com/bizhenghe/p/14026101.html