递归方法遍历多层传参

public static void paramter(Object object) {

//判断传入参数是否为Null
if (object != null) {
if (object instanceof String || object instanceof Integer || object instanceof Long || object instanceof Float || object instanceof Boolean
|| object instanceof Double) {
System.out.println(object);
} else if (object instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(sdf.format(object));
} else if (object instanceof List) {
List li = (List) object;
for (int j = 0; j < li.size(); j++) {
paramter(li.get(j));
}
} else if (object instanceof Map) {
Map<String, Object> map = (Map<String, Object>) object;
Set<String> mapset = map.keySet();
for (String string : mapset) {
paramter(map.get(string));
}
}
}
}

public static void main(String[] args) {
List list1 = new ArrayList();
List list2 = new ArrayList();
List list3 = new ArrayList();
Map<String, String> map = new HashMap<String, String>();
map.put("id1", "wang");
map.put("id2", "sheng");
list3.add(map);
list3.add(12);
list3.add(13);
list3.add(true);
list3.add(new Date());
list2.add(list3);
list2.add("aa");
list2.add("bb");
list1.add(list2);
paramter(list1);
}

posted @ 2017-07-31 10:25  santian  阅读(488)  评论(0编辑  收藏  举报