zoukankan      html  css  js  c++  java
  • Arrays.toString() 的用法

    在做项目的时候很想看一下数组里面具体放的数据,于是我直接打印了数组,但是结果是输出的居然是数组的地址,咕~~(╯﹏╰)b      

    于是查了一下,怎样才能将数组输出,找到了Arrays.toString() ,下面是在Arrays类里面这个方法的具体实现方法,我们不用管具体是怎么实现的,只要会使用就可以啦。

    public class MaoPao2 {
        public static void main(String[] args) {
            int[] nums = {76, 23, 9, 8, 88};
            for (int i = 0; i < nums.length - 1; i++) {//比较的轮数;
                for (int j = 0; j < nums.length - 1 - i; j++) {
                    int temp;
                    if (nums[j] > nums[j + 1]) {
                        temp = nums[j];
                        nums[j] = nums[j + 1];
                        nums[j + 1] = temp;
                    }
                }
            }
            //增强型for
            for (int num : nums) {
                System.out.print("("+nums+"我是nums)	");
                System.out.print(num + "	");
            }
        }
    }

    运行内容:

    对比:

    使用Arrays.toString():

    运行内容

    这个方法是是用来将数组转换成String类型输出的,入参可以是long,float,double,int,boolean,byte,object
    型的数组。

    最后感谢强大的IDEA代码提醒功能。

  • 相关阅读:
    构造函数
    时延(delay,latency)
    吞吐量
    带宽(band-width)
    单位
    bps
    比特(bit)
    速率
    C语言中的“>>”和“<<”
    C#中unit
  • 原文地址:https://www.cnblogs.com/appleworld/p/11963420.html
Copyright © 2011-2022 走看看