You have a Map<Long, Bigdecimal>, remove all the entries from the map whose value is zero. Do it using java 8

Sanjay Singh
1 min readOct 15, 2019

--

package com.core.test.box;

import java.math.BigDecimal;

import java.util.HashMap;

import java.util.Map;

public class Example {

public static void main(String[] args) {

BigDecimal bd1 = new BigDecimal(“0”);

BigDecimal bd2 = new BigDecimal(“0”);

BigDecimal bd3 = new BigDecimal(“400”);

Long l1 = new Long(20);

Long l2 = new Long(10);

Long l3 = new Long(30);

Map<Long, BigDecimal> map = new HashMap<>();

map.put(l1, bd1);

map.put(l2, bd2);

map.put(l3, bd3);

System.out.println(map);

map.values().removeIf(b->b.intValue()==0);

System.out.println(map);

}

}

--

--

Sanjay Singh
Sanjay Singh

Written by Sanjay Singh

Java, Spring Boot & Microservices developer Sharing knowledge, tutorials & coding tips on my Medium page. Follow me for insights & see story list section

No responses yet