Search This Blog

Total Pageviews

Java 8 HashMap Streaming Example

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())

        System.out.println("Sreaming example : " + streamResult );



Petter Marry said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

Kanye Co Jamila said...

Great Article
IEEE Final Year Projects for CSE
IEEE Project Centers in Chennai

Best Client Optimized Programming Language for Mobile Development?

Use Google's Dart language, which is Object-oriented, class-based and garbage-collected language with C-Style.  Dart can compile to eith...