java数组反射实现动态的判断一个对象是否是数组并且对数组进行拆包输出
public static Map<String, String> maptoMapString(Map<String, ?> map) {
return map.entrySet().stream().collect(Collectors.toMap(
(entry) -> {
return entry.getKey();
},
(entry) -> {
if(entry.getValue().getClass().isArray()) {
StringBuilder sb = new StringBuilder();
for(int i=0; i<Array.getLength(entry.getValue()); ++i) {
Object obj = Array.get(entry.getValue(), i);
sb.append(obj.toString()).append(",");
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
} else {
return entry.getValue().toString();
}
}
));
}
本文来自博客园,作者:hjzqyx,转载请注明原文链接:https://www.cnblogs.com/hujunzheng/p/7215373.html