您现在的位置是:首页 >
当前栏目
you might not need peek
not you need peek might
2023-06-13 09:11:17 时间
上代码
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Scratch {
public static void main(String[] args) {
class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
'}';
}
}
Map<Integer, List<User>> userMap = new HashMap<>();
userMap.put(1, Stream.generate(User::new).limit(3).collect(Collectors.toList()));
// 我以前的写法
userMap.put(1, userMap.get(1).stream().peek(u -> u.setName("吉良吉影")).collect(Collectors.toList()));
// 我今天发现实际上这么写就可以了
userMap.get(1).forEach(u -> u.setName("吉良吉影"));
userMap.get(1).forEach(System.out::println);
}
}
这是因为forEach
中进行操作会改变原集合对象
相关文章
- not for you什么意思_issue to
- 【Nginx】host not found in upstream
- ORA-00322: log string of thread string is not current copy ORACLE 报错 故障修复 远程处理
- ORA-00443: background process “string” did not start ORACLE 报错 故障修复 远程处理
- ORA-01193: file string is not the same file seen at start of recovery ORACLE 报错 故障修复 远程处理
- ORA-25127: RELY not allowed in NOT NULL constraint ORACLE 报错 故障修复 远程处理
- ORA-31530: could not find published column string for CDC subscriber view string.string ORACLE 报错 故障修复 远程处理
- MySQL Error number: 3179; Symbol: ER_MASTER_KEY_ROTATION_NOT_SUPPORTED_BY_SE; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-48492: The report component name is not defined ORACLE 报错 故障修复 远程处理
- ORA-00846: could not shrink MEMORY_TARGET to specified value ORACLE 报错 故障修复 远程处理
- ORA-09275: CONNECT INTERNAL is not a valid DBA connection ORACLE 报错 故障修复 远程处理
- ORA-12674: Shared server: proxy context not saved ORACLE 报错 故障修复 远程处理
- not connectingMAMP MySQL Not Connecting: Solutions at a Glance(mampmysql)
- MySQL中使用NOT操作符匹配多个条件(mysql中not多个)
- MySQL判断字段非空使用NOT NULL约束条件确保数据完整性(mysql中判断字段非空)