Java tutorial
//package com.java2s; //License from project: Creative Commons License import java.util.HashMap; import java.util.Map; import java.util.function.Predicate; public class Main { /** * Checks if a value userExists in a HashMap that matches the specified Predicate. * @param map the HashMap to check against * @param condition the Predicate to check * @param <K> the type of the Key in the HashMap * @param <V> the type of the Value in the HashMap * @return true if condition is true * @throws IllegalArgumentException if HashMap or Predicate is null */ public static <K, V> boolean doesItemExistInHashMap(final HashMap<K, V> map, final Predicate<V> condition) { if (map == null) throw new IllegalArgumentException("HashMap cannot be null!"); if (condition == null) throw new IllegalArgumentException("Predicate cannot be null!"); for (final Map.Entry<K, V> entry : map.entrySet()) if (condition.test(entry.getValue())) return true; return false; } }