java 8 , merge()
import java.util.HashMap;
import java.util.Map; public class j8merge { public static void main(String[] args) { // java 8 , merge() Map<String,Integer> map=new HashMap<>();
map.put("A", );
map.put("B", );
map.put("C", ); // add new key value ("A",99), if key "A" exist in map then do function "(X,Y) -> (Y+X)" ,the function return value will replace the oldvalue.
Integer newValue1 = map.merge("A", , (X,Y) -> (Y+X));
Integer newValue2 = map.merge("A", , (X,Y) -> Y);
// add new key value ("D",666), if key "D" not exist in map then insert the key value to map
Integer newValue3 = map.merge("D", , (X,Y) -> Y);
Integer newValue4 = map.merge(null, , (X,Y) -> Y);
Integer newValue5 = map.merge(null, , (X,Y) -> Y); for(String s:map.keySet()){
System.out.println(s+" : "+map.get(s));
} }
/*
null : 5555
A : 888
B : 2000
C : 3000
D : 666
*/
}
java 8 , merge()的更多相关文章
- LeetCode第[21][23]题(Java):Merge Sorted Lists
题目:合并两个已排序链表 难度:Easy 题目内容: Merge two sorted linked lists and return it as a new list. The new list s ...
- LeetCode第[88]题(Java):Merge Sorted Array(合并已排序数组)
题目:合并已排序数组 难度:Easy 题目内容: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as ...
- LeetCode第[56]题(Java):Merge Intervals
题目:合并区间 难度:Medium 题目内容: Given a collection of intervals, merge all overlapping intervals. 翻译: 给定一个 ...
- 【JAVA】merge two array by order
public class MergeSort { static void show(int a[]) { int i; for (i = 0; i < a.length; i++) { Syst ...
- Java Algorithm Problems
Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...
- Java IO 流 -- 随机读取和写入流 RandomAccessFile (文件分割和合并)
RandomAccessFile 相对其它流多了一个seek() 方法指定指针的偏移量. 1.指定起始位置读取剩余内容 public static void test01() throws IOExc ...
- 代码覆盖率工具 EMMA
使用 EMMA 获得功能测试覆盖率 测试覆盖率是评价测试完整性的重要的度量标准之一. EMMA 是一个面向 Java 代码的测试覆盖率收集工具.在测试过程中,使用 EMMA 能使收集和报告测试覆盖率的 ...
- Set vs. Set<?>(转)
You may know that an unbounded wildcard Set<?> can hold elements of any type, and a raw type S ...
- close()方法应该在finally语句中调用吗?
翻译人员: 铁锚 翻译时间: 2013年12月20日 原文链接: Should .close() be put in finally block or not? 下面列出了关闭输出流(output w ...
随机推荐
- org.hibernate.AssertionFailure: null id in com.you.model.User entry (don't flush the Session after a
1.错误描写叙述 org.hibernate.AssertionFailure: null id in com.you.model.User entry (don't flush the Sessio ...
- poj--3984--迷宫问题(bfs+路径记录)
迷宫问题 Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit Status D ...
- Elasticsearch之四种查询类型和搜索原理(博主推荐)
Elasticsearch Client发送搜索请求,某个索引库,一般默认是5个分片(shard). 它返回的时候,由各个分片汇总结果回来. 官网API https://www.elastic.co/ ...
- 005.JMS可靠性机制
1. 消息接收确认 JMS消息只有在被确认之后,才认为已经被成功地消费了.消息的成功消费通常包含三个阶段: 客户接收消息 客户处理消息 消息被确认 在事务性会话中,当一个事务被提交的时候,确认自动发生 ...
- POJ 1979 Red and Black (简单dfs)
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...
- QT笔记 -- (5) 实现QWidget的paintEvent函数,在widget上画背景图形
如图,想在界面上画个弧线和直线,于是继承QWidget得到类MainContainer,并实现了paintEvent函数.然后用类MainContainer定义centralWidget. MainC ...
- POJ 3278 Catch That Cow【BFS】
题意:给出n,k,其中n可以加1,可以减1,可以乘以2,问至少通过多少次变化使其变成k 可以先画出样例的部分状态空间树 可以知道搜索到的深度即为所需要的最小的变化次数 下面是学习的代码----@_@ ...
- SQL Server查询死锁,杀死进程解决死锁
查询死锁进程和表 SELECT request_session_id AS spid , OBJECT_NAME(resource_associated_entity_id) AS 'table' F ...
- PHP十六个魔术方法
PHP中把以两个下划线__开头的方法称为魔术方法(Magic methods),这些方法在PHP中充当了举足轻重的作用. 魔术方法包括: __construct(),类的构造函数 __destruct ...
- 解决PNG图片在IE6中背景不透明方法_解决IE6中PNG背
解决PNG图片在IE6中背景不透明方法_解决IE6中PNG背 目录 解决代码 解决png图片在html中 解决png作为网页背景-css 1.解决PNG图片在IE6中背景不透明的CSS与JS代码 ...