示例#1
0
 public static void main(String args[]) {
   Map<String, String> in = new HashMap<>();
   in.put("val1", "10.0");
   in.put("val2", "60.0");
   Map<String, Float> mOriginal = filterLoadedValues(in);
   Map<String, Float> mLambda = filterLoadedValuesLambda(in);
   System.out.println("\nOriginal Entries\n--");
   mOriginal.entrySet().stream().forEach(TransformMap::printEntry);
   System.out.println("\nLambda Entries\n--");
   mLambda.entrySet().stream().forEach(TransformMap::printEntry);
 }
示例#2
0
 public static Map filterLoadedValuesLambda(Map<String, String> in) {
   return in.entrySet()
       .stream()
       .collect(
           Collectors.toMap(
               e -> e.getKey().toString(), e -> Float.valueOf(e.getValue().toString())));
 }
示例#3
0
 public static Map filterLoadedValues(Map<String, String> in) {
   Map<String, Float> out = new HashMap<>();
   for (Iterator iterator = in.entrySet().iterator(); iterator.hasNext(); ) {
     Map.Entry entry = (Map.Entry) iterator.next();
     out.put(entry.getKey().toString(), Float.valueOf(entry.getValue().toString()));
   }
   return out;
 }