1、如果使用map的时候,担心key重复,覆盖掉值
那么直接加个if/else判断就好了。
如果map.containsKey,那么就把值追加上去,否则就直接put。
2、list的removeAll方法
list.removeAll(list2);//list要removeAll谁,就是看list自己比另个list多什么元素。
//反过来,list2.removeAll(list);比如就是看list比list2缺少什么元素。
3、 implements Serializable 干嘛的
为了实现序列化。
为什么要实现序列化?
如果要在网络上传输或接口间传输,保存到数据库。可以通过实现序列化,使得序列化和反序列化后的结果一致。
4、 lambda表达式里list 要 final 为啥呀
可能是因为lambda底层是迭代器,迭代器不允许修改集合的size
5 、list转map 用stream流
list.stream.collect.(Collectors.toMap(a->a.getName,a->a.getAge));//age作为value
list.stream.collect.(Collectors.toMap(a->a.getName,Function.identity));//整个对象作为value
6、BeanUtils.copyProperties
BeanUtils.copyProperties(person,person2);拷贝的时候,默认是按照属性名进行拷贝,如果目标对象没有对应名称的属性,则会被忽略。
比如,
Person person = new Person();person.setAge(1);person.setName("一");Person person2 = new Person();person.setName("二");person.setCity("北京");BeanUtils.copyProperties(person,person2);System.out.println(person2);//输出结果Person(age=1, name=二, city=北京)