SHARE
TWEET

delete by predicate

DulcetAirman Feb 5th, 2018 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch.claude_martin;
  2.  
  3. import java.util.HashMap;
  4.  
  5. public class SomeClass {
  6.     public static void main(String[] args) {
  7.         HashMap<Integer, String> map = new HashMap<>();
  8.         map.put(1, "foo");
  9.         map.put(2, "bar");
  10.         map.put(3, "qux");
  11.         map.put(4, "grault");
  12.         map.put(5, "garply");
  13.         map.put(6, "thud");
  14.         map.put(7, "flob");
  15.         System.out.println(map);
  16.         // {1=foo, 2=bar, 3=qux, 4=grault, 5=garply, 6=thud, 7=flob}
  17.  
  18.         // delete by predicate
  19.         map.entrySet().removeIf(e -> e.getValue().startsWith("f"));
  20.  
  21.         System.out.println(map);
  22.         // {2=bar, 3=qux, 4=grault, 5=garply, 6=thud}
  23.     }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top