public void printArray(){
String[] array = new String[]{"a","c","q","t","y"};
objectPrint(array);
objectPrint("xyz");
}
public void objectPrint(Object obj) {
Class<?> clazz = obj.getClass();
//判断传入的数据类型是否为数组
if(clazz.isArray()){
int length = Array.getLength(obj);
for (int i = 0; i < length; i++) {
System.out.println(Array.get(obj, i));
}
}else{
System.out.println(obj);
}
} |
|