Since you specifically said that you had a Map<Object,List<Object>>, I will limit this to that scenario.
First, create some test data.
Map<Object, List<Object>> halls = Map.of(new MyClass(1),
List.of("G", "H"), new MyClass(4), List.of("C", "D"),
new MyClass(7), List.of("A", "B"), new MyClass(3),
List.of("E", "F"));
Now sort the existing map. To preserve the sort you can used a LinkedHashMap which will maintain the insertion order. However, newly added items will not be sorted but simply added to the end.
In this case you must cast the key to your actual class name to obtain the seats as Object knows nothing about that method. To reverse the sort, just reverse the order of e1 and e2 in the Integer.compare method. Had you used MyClass as the key and not Object, this could have been somewhat easier.
Map<Object, List<Object>> result = halls.entrySet().stream()
.sorted((e1, e2) -> Integer.compare(
((MyClass) e2.getKey()).getSeatsNumber(),
((MyClass) e1.getKey()).getSeatsNumber()))
.collect(Collectors.toMap(Entry::getKey,
Entry::getValue, (a, b) -> a,
LinkedHashMap::new));
result.entrySet().forEach(System.out::println);
The above prints.
seats:7=[A, B]
seats:4=[C, D]
seats:3=[E, F]
seats:1=[G, H]
And here is the test class with a toString override included.
class MyClass {
int seats = 0;
public MyClass(int seats) {
this.seats = seats;
}
public int getSeatsNumber() {
return seats;
}
public String toString() {
return "seats:"+seats;
}
}