Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ch.claude_martin;
- import java.util.HashMap;
- public class SomeClass {
- public static void main(String[] args) {
- HashMap<Integer, String> map = new HashMap<>();
- map.put(1, "foo");
- map.put(2, "bar");
- map.put(3, "qux");
- map.put(4, "grault");
- map.put(5, "garply");
- map.put(6, "thud");
- map.put(7, "flob");
- System.out.println(map);
- // {1=foo, 2=bar, 3=qux, 4=grault, 5=garply, 6=thud, 7=flob}
- // delete by predicate
- map.entrySet().removeIf(e -> e.getValue().startsWith("f"));
- System.out.println(map);
- // {2=bar, 3=qux, 4=grault, 5=garply, 6=thud}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement