zoukankan      html  css  js  c++  java
  • java中打印数组

    public class IOTools {
        public static void print(int[] nums) {
            System.out.print("[");
            if (nums.length == 0) {
                System.out.println("]");
                return;
            }
            for (int i = 0; i < nums.length - 1; i ++) {
                System.out.print(nums[i] + " ");
            }
            System.out.print(nums[nums.length - 1]);
            System.out.println("]");
        }
    
        public static void print(char[] chars) {
            System.out.print("[");
            if (chars.length == 0) {
                System.out.println("]");
                return;
            }
            for (int i = 0; i < chars.length - 1; i ++) {
                System.out.print(chars[i] + " ");
            }
            System.out.print(chars[chars.length - 1]);
            System.out.println("]");
        }
    
        public static void print(boolean[] booleans) {
            System.out.print("[");
            if (booleans.length == 0) {
                System.out.println("]");
                return;
            }
            for (int i = 0; i < booleans.length - 1; i ++) {
                System.out.print(booleans[i] + " ");
            }
            System.out.print(booleans[booleans.length - 1]);
            System.out.println("]");
        }
    
        public static void print(String[] strings) {
            System.out.print("[");
            if (strings.length == 0) {
                System.out.println("]");
                return;
            }
            for (int i = 0; i < strings.length - 1; i ++) {
                System.out.print(strings[i] + " ");
            }
            System.out.print(strings[strings.length - 1]);
            System.out.println("]");
        }
    
        public static void print(boolean[][] booleans) {
            System.out.print("[
    ");
            if (booleans.length == 0) {
                System.out.println("]");
                return;
            }
            for (int i = 0; i < booleans.length - 1; i ++) {
                print(booleans[i]);
            }
            print(booleans[booleans.length - 1]);
            System.out.println("]");
        }
    
        public static void print(char[][] chars) {
            if (chars == null || chars.length == 0) {
                System.out.println("[]");
                return;
            }
            System.out.print("[
    ");
            for (int i = 0; i < chars.length - 1; i ++) {
                print(chars[i]);
            }
            print(chars[chars.length - 1]);
            System.out.println("]");
        }
    
        public static void print(int[][] nums) {
            System.out.print("[
    ");
            if (nums.length == 0) {
                System.out.println("]");
                return;
            }
            for (int i = 0; i < nums.length - 1; i ++) {
                print(nums[i]);
            }
            print(nums[nums.length - 1]);
            System.out.println("]");
        }
    
        public static void print(int num) {
            System.out.println(num);
        }
    
        public static void print(char num) {
            System.out.println(num);
        }
    
        public static void print(String str) {
            System.out.println(str);
        }
    
        public static void print(boolean bool) {
            System.out.println(bool);
        }
    
        public static void print(Collection<?> collection) {System.out.println(collection);}
    
    }
    
    

    在要调用的代码的开头加上:

    import static XXX.print;
    

    把其中的XXX替换成自己的包的位置(当然,如果用的是IDEA的话,是可以自己添加上的)。

  • 相关阅读:
    由自身经历谈“不谋全局者,不足以谋一域”
    MySQL 常用SQL语句
    举例说明android中ListPreference的使用方法
    cookie机制和session机制的区别
    thinkphp浏览历史功能实现方法
    利用PHP获取访客IP、地区位置、浏览器及来源页面等信息
    PHP+Ajax点击加载更多内容 -这个效果好,速度快,只能点击更多加载,不能滚动自动加载...
    php用正则表达式匹配URL的简单方法(亲测可行)
    PHP实现记录浏览历史页面
    [译] 流言终结者 —— “SQL Server 是Sybase的产品而不是微软的”
  • 原文地址:https://www.cnblogs.com/liulaolaiu/p/11744400.html
Copyright © 2011-2022 走看看