I have a list that I need to custom sort and then convert to a map with its Id vs. name map.
Here is my code:
Map<Long, String> map = new LinkedHashMap<>();
list.stream().sorted(Comparator.comparing(Building::getName)).forEach(b-> map.put(b.getId(), b.getName()));
I think this will do the job but I wonder if I can avoid creating LinkedHashMap
here and use fancy functional programming to do the job in one line.