Skip to content

Instantly share code, notes, and snippets.

@mikebroberts
Created March 14, 2017 15:33
Show Gist options
  • Save mikebroberts/19e4cd5bab32d5b4146ea065678e4bb6 to your computer and use it in GitHub Desktop.
Save mikebroberts/19e4cd5bab32d5b4146ea065678e4bb6 to your computer and use it in GitHub Desktop.
package io.symphonia;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ListMapLambda {
public List<Integer> handlerList(List<Integer> input) {
List<Integer> newList = new ArrayList<>();
input.forEach(x -> newList.add(100 + x));
return newList;
}
public Map<String,String> handlerMap(Map<String,String> input) {
Map<String, String> newMap = new HashMap<>();
input.forEach((k, v) -> newMap.put("New Map -> " + k, v));
return newMap;
}
public Map<String,Map<String, Integer>> handlerNestedCollection(List<Map<String, Integer>> input) {
Map<String, Map<String, Integer>> newMap = new HashMap<>();
IntStream.range(0, input.size())
.forEach(i -> newMap.put("Nested at position " + i, input.get(i)));
return newMap;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment