top.doudou.core.util.FastPrint Maven / Gradle / Ivy
package top.doudou.core.util;
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 FastPrint {
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());
}
/**
* 打印二维数组
* @param array
*/
public static void printArray(int[][] array){
for (int i = 0 ; i < array.length ; i++){
for (int j = 0 ; j < array[i].length ; j++){
System.out.print(array[i][j] + "\t");
}
System.out.println();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy