{{theTime}}

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())
                .collect(Collectors.joining());

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

    }
}

2 comments:

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

Java Script GET request Sample Code

fetch(' https://api.public.com/api ')   .then(response => response.json())   .then(data => console.log(data))   .catch(error =...