1、去除list中的null元素
public static <T> List<T> removeNull(List<? extends T> oldList) {
oldList.removeAll(Collections.singleton(null));
return (List<T>)oldList;
}
public static <T> List<T> removeNull(List<? extends T> oldList) {
List<T> listTemp = new ArrayList();
for (int i = 0; i < oldList.size(); i ++) {
if (oldList.get(i) != null) {
listTemp.add(oldList.get(i));
}
}
return listTemp;
}
2、初始化map
Map<String, String> map = new HashMap<String, String>() {{
put("key1", "value1");
put("key2", "value2");
put("key3", "value3");
}};
3、map的修改细节
public static void main(String[] args) {
Map<String, Object> map = new HashMap<>();
map.put("status", Boolean.False);
Map<String, Object> main = new HashMap<>();
main.put("map", map);
System.out.println(main.getOrDefault("map", 0));
map.put("data", 111);
System.out.println(main.getOrDefault("map", 0));
}
4、初始化list
List list = new ArrayList<>(Arrays.asList("1", "2", "3"));