Skip to content

Instantly share code, notes, and snippets.

@carlosmaniero
Created March 17, 2017 22:29
Show Gist options
  • Save carlosmaniero/471f00b56f0c012dfe79182eb278dc9f to your computer and use it in GitHub Desktop.
Save carlosmaniero/471f00b56f0c012dfe79182eb278dc9f to your computer and use it in GitHub Desktop.
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