0

I have a HashMap HashMap<String, List<OtherModel>> - I need to sort by the field of the first List<OtherModel> element, have any ideas?)

I have incorrect code for example:

 public static HashMap<String, List<AsoInfoModel>> sortAsoByValue(HashMap<String, List<AsoInfoModel>> items) {
        List<Map.Entry<String, List<AsoInfoModel>>> list = new LinkedList<>(items.entrySet());
        list.stream().sorted(Comparator.comparing(Map.Entry::getValue::AsoInfoModel::position, Comparator.naturalOrder());

        HashMap<String, List<AsoInfoModel>> temp = new LinkedHashMap<>();
        for (Map.Entry<String, List<AsoInfoModel>> aa : list) {
            temp.put(aa.getKey(), aa.getValue());
        }
        return temp;
    }
  • 1
    Help us help you - share some sample data and the result you're trying to get for it – Mureinik Nov 25 '20 at 08:44
  • 1
    Does this answer your question? [Sort a Map by values](https://stackoverflow.com/questions/109383/sort-a-mapkey-value-by-values) – maloomeister Nov 25 '20 at 08:45

0 Answers0