返回结果
{count=1, name=2}
merge方法在统计时用的场景比较多,这里举一个统计学生总成绩的例子来说明。现在有一个学生各科成绩的集合,要统计每个学生的总成绩,以下给出使用merge方法与不使用的写法
public class StudentScoreSum {
@Data
static class StudentScore {
private Integer sid;
private String scoreName;
private Integer score;
public StudentScore(Integer sid, String scoreName, Integer score) {
this.sid = sid;
this.scoreName = scoreName;
this.score = score;
}
public StudentScore() {
}
}
public static void main(String[] args) {
List list = new ArrayList<>();
list.add(new StudentScore(1, “chinese”, 110));
list.add(new StudentScore(1, “english”, 120));
list.add(new StudentScore(1, “math”, 135));
list.add(new StudentScore(2, “chinese”, 99));
list.add(new StudentScore(2, “english”, 100));
list.add(new StudentScore(2, “math”, 133));
list.add(new StudentScore(3, “chinese”, 88));
list.add(new StudentScore(3, “english”, 140));
list.add(new StudentScore(3, “math”, 90));
list.add(new StudentScore(4, “chinese”, 108));
list.add(new StudentScore(4, “english”, 123));
list.add(new StudentScore(4, “math”, 114));
list.add(new StudentScore(5, “chinese”, 116));
list.add(new StudentScore(5, “english”, 133));
list.add(new StudentScore(5, “math”, 135));
System.out.println(sum1(list));
System.out.println(sum2(list));
}
//传统写法
public static Map<Integer, Integer> sum1(List list) {
Map<Integer, Integer> map = new HashMap<>();
for (StudentScore studentScore : list) {
if (map.containsKey(studentScore.getSid())) {
map.put(studentScore.getSid(),
map.get(studentScore.getSid()) + studentScore.getScore());
} else {
map.put(studentScore.getSid(), studentScore.getScore());
}
}
return map;
}
//merger写法
public static Map<Integer, Integer> sum2(List list) {
Map<Integer, Integer> map = new HashMap<>();
list.stream().forEach(studentScore -> map.merge(studentScore.getSid()
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注Java获取)
![img](https://img-blog.csdnimg.cn/img_convert/b2c0fdf5ba22ba5f7140d56d188faf10.jpeg)
总结
这份面试题几乎包含了他在一年内遇到的所有面试题以及答案,甚至包括面试中的细节对话以及语录,可谓是细节到极致,甚至简历优化和怎么投简历更容易得到面试机会也包括在内!也包括教你怎么去获得一些大厂,比如阿里,腾讯的内推名额!
某位名人说过成功是靠99%的汗水和1%的机遇得到的,而你想获得那1%的机遇你首先就得付出99%的汗水!你只有朝着你的目标一步一步坚持不懈的走下去你才能有机会获得成功!
成功只会留给那些有准备的人!
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
有准备的人!
[外链图片转存中…(img-T8ygUujV-1712979335161)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!