Created
March 17, 2017 22:29
-
-
Save carlosmaniero/471f00b56f0c012dfe79182eb278dc9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
public class StreamMap { | |
public static void main(String args[]) { | |
Map<String, Integer> fruits = new HashMap<>(); | |
fruits.put("Banana", 7); | |
fruits.put("Apple", 2); | |
fruits.put("Kiwi", 1); | |
int totalOfFruits = fruits.keySet().stream() | |
.mapToInt(fruits::get).sum(); | |
System.out.println(totalOfFruits); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment