asp网站会员注册不了,在线图片编辑器手机版,重要新闻今天8条新闻,永不倒闭的10大央企1、如果使用map的时候#xff0c;担心key重复#xff0c;覆盖掉值
那么直接加个if/else判断就好了。
如果map.containsKey#xff0c;那么就把值追加上去#xff0c;否则就直接put。 2、list的removeAll方法
list.removeAll(list2);//list要removeAll谁,就是看list自己比…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(age1, name二, city北京)