top.doudou.common.tool.utils.Fast Maven / Gradle / Ivy
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());
}
}