All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.doudou.common.tool.utils.Fast Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package top.doudou.common.tool.utils;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;

/**
 * @Description 打印工具类
 * @Author 傻男人 <[email protected]>
 * @Date 2020-10-20 9:58
 * @Version V1.0
 */
public class Fast {

    public static void print(Object obj){
        if(null == obj){
            System.out.println("null");
            return;
        }
        if(obj instanceof Map){
            ((Map) obj).forEach((key,value)-> System.out.print("["+key+":"+value+"],"));
            System.out.println();
            return;
        }
        if(obj instanceof Collection){
            ((Collection) obj).forEach(item-> System.out.print("["+item.toString()+"],"));
            System.out.println();
            return;
        }
        if(obj.getClass().isArray()){
            int length = Array.getLength(obj);
            if(length == 0){
                System.out.println("[]");
                return;
            }
            System.out.print("[");
            for (int i = 0; i < length; i++) {
                if(i != length-1){
                    System.out.print(Array.get(obj,i)+",");
                }else {
                    System.out.print(Array.get(obj,i));
                }
            }
            System.out.print("]");
            System.out.println();
            return;
        }
        System.out.println(obj.toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy