Java Lambda: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
<source lang="java">
<source lang="java">
Map<String, String> insured = Stream.of("Adults:1", "Children:1", "Senior Citizen:10")
Map<String, String> insured = Stream.of("Adults:1", "Children:1", "Senior Citizen:10")
                                     .map(pair -> pair.split(":"))
                                     .map(pair -> pair.split(":")).collect(Collectors.toMap(pair -> pair[0], pair->pair[1]));
                                    .collect(Collectors.toMap(array -> array[0], array->array[1]));
</source>
</source>



Revision as of 22:28, 5 September 2021

Map<String, String> insured = Stream.of("Adults:1", "Children:1", "Senior Citizen:10")
                                    .map(pair -> pair.split(":")).collect(Collectors.toMap(pair -> pair[0], pair->pair[1]));


References