Мой список похож на
List<Map<String, Object>> sortedList = new ArrayList<>();
где мой список как,
[{column_changed = first_name, sequence_number = 190001, change_date = 2019-01-01, customer_number = 3100},
{column_changed = last_name, sequence_number = 190001, change_date = 2019-01-01, customer_number = 3100},
{column_changed = mail_id, sequence_number = 19002, change_date = 2019-01-05, customer_number = 3101},
{column_changed = date_of_birth, sequence_number = 190002, change_date = 2019-01-05, customer_number = 3101},
{column_changed = национальность, sequence_number = 190002, change_date = 2019-01-05, customer_number = 3101},
{column_changed = contact_number, sequence_number = 19003, change_date = 2019-01-10, customer_number = 3102}]
Я инициализирую экземпляр Map следующим образом,
Map<String, List<Map<String, Object>>> mySortedMap = new TreeMap<>();
Когда я использую Collectors.groupingBy () с использованием sequence_number,
mySortedMap = sortedList.stream().collect(Collectors.groupingBy(change -> (String)change.get("sequence_number")));
вывод выглядит следующим образом,
{190001 = [{column_changed = first_name, sequence_number = 190001, change_date = 2019-01-01, customer_number = 3100},
{column_changed = last_name, sequence_number = 190001, change_date = 2019-01-01, customer_number = 3100}],
19003 = [{column_changed = contact_number, sequence_number = 19003, change_date = 2019-01-10, customer_number = 3102}],
19002 = [{column_changed = mail_id, sequence_number = 19002, change_date = 2019-01-05, customer_number = 3101},
{column_changed = date_of_birth, sequence_number = 190002, change_date = 2019-01-05, customer_number = 3101},
{column_changed = национальность, sequence_number = 190002, change_date = 2019-01-05, customer_number = 3101}]}
Но мне нужно ключи для сортировки . Хотя экземпляр является TreeMap, ключи не отсортированы. Я не мог понять, почему. Может ли кто-нибудь помочь мне с этим.