import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class JavaStreamExample {
    public static void main(String[] args) {
        Map<Integer, String> countryMap = new HashMap<>();
        countryMap.put(1, "USA");
        countryMap.put(2, "UK");
        countryMap.put(3, "AUSTRALIA");
        countryMap.put(4, "BRAZIL");
         for (Map.Entry<Integer, String> entry : countryMap.entrySet()) {
            if ("BRAZIL".equals(entry.getValue())) {
                System.out.println( " Before Java 8 : " +entry.getValue());
            }
        }
         String streamResult = countryMap.entrySet().stream()
                .filter(map -> "BRAZIL".equals(map.getValue()))
                .map(map -> map.getValue())
                .collect(Collectors.joining());
        System.out.println("Sreaming example : " + streamResult );
    }
}
 
 
No comments:
Post a Comment