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:
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.
Great Article
IEEE Final Year Projects for CSE
IEEE Project Centers in Chennai
Post a Comment