首页 > 编程语言 > 详细

Java数组05——Arrays类

时间:2021-07-29 01:01:27      阅读:22      评论:0      收藏:0      [点我收藏+]

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]+", ");
            }
 ?
 ?
        }
    }
 }
 ?

 

Java数组05——Arrays类

原文:https://www.cnblogs.com/lwtyyds/p/15072962.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!