Skip to content

Commit 695b096

Browse files
authored
Create mapAB2.java
Modify and return the given map as follows: if the keys "a" and "b" are both in the map and have equal values, remove them both. mapAB2({"a": "aaa", "b": "aaa", "c": "cake"}) → {"c": "cake"} mapAB2({"a": "aaa", "b": "bbb"}) → {"a": "aaa", "b": "bbb"} mapAB2({"a": "aaa", "b": "bbb", "c": "aaa"}) → {"a": "aaa", "b": "bbb", "c": "aaa"}
1 parent 1037e4e commit 695b096

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Map-1/mapAB2.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
Modify and return the given map as follows: if the keys "a" and "b" are both in the map and have equal values, remove them both.
3+
4+
mapAB2({"a": "aaa", "b": "aaa", "c": "cake"}) → {"c": "cake"}
5+
mapAB2({"a": "aaa", "b": "bbb"}) → {"a": "aaa", "b": "bbb"}
6+
mapAB2({"a": "aaa", "b": "bbb", "c": "aaa"}) → {"a": "aaa", "b": "bbb", "c": "aaa"}
7+
*/
8+
public Map<String, String> mapAB2(Map<String, String> map) {
9+
String temp1 = map.get("a");
10+
String temp2 = map.get("b");
11+
if( temp1!= null && temp2!= null && temp1.equals(temp2) ) {
12+
map.remove("a");
13+
map.remove("b");
14+
}
15+
return map;
16+
}

0 commit comments

Comments
 (0)