/** * @author lautturi.com * Java example: removing element with specific value from a map in java */ import java.util.*; public class Lautturi { public static void main(String[] args) { HashMap<Integer, String> map = new HashMap<Integer, String>(); // Put elements in Map map.put(1, "Apple"); map.put(2, "Banana"); map.put(3, "Cherry"); map.put(4, "Orange"); map.put(5, "Lautturi"); System.out.println(map); map.entrySet().removeIf(e -> e.getValue().equals("Orange")); System.out.println(map); } }Source:www.lautturi.com
output:
{1=Apple, 2=Banana, 3=Cherry, 4=Orange, 5=Lautturi} {1=Apple, 2=Banana, 3=Cherry, 5=Lautturi}