Are there standard packages in java 7 for grouping and sorting

list<map<String,Object>> 

?

This is a set of rows in which the data lie By column names, View so to speak tables with columns.

For example, an object contains a report, each line of which contains 5 entities (id1..id5 - unique identifiers of entities, sum1-sum5 - the corresponding amounts and date1-date5 - dates).

you need to sort the strings based on grouping by all id, group by date, inside the group - by amount.

  • In what sense to group? What kind of solution do you want to get? - IL Mare
  • At the output, rearrange the lines in places without changing the data - Denis

1 answer 1

There is no standard sorting sheet consisting of MAP. For this, the interface map must be inherited from the Comparable interface, but these are two different concepts.

You can use the method

 Collections.sort(List<T> list, Comparator<? super T> c) 

But even in this case, you have to write your comparator for the map.

As for sorting the contents of the map, you can use the TreeMap class. Without a comparator, the data will be sorted in natural order, with a comparator - both write and sort.

  • It is required to sort the list, and use map only as a set of values. Sort the sheet, as I understand it will have to take into account 5 groups, for which you still need to find the aggregate values ​​of individual keys (such as min (), max () or sum ()) and take all this into account in the stack when sorting ... , I want to understand whether there are standard offers on the market or not; ( - Denis
  • Are there classic packages for grouping / sorting data? I heard that it is possible to write almost on data sets! - Denis
  • Arrays and Collections sort the primitive types in their natural order, and objects - either by the interface of Comparable objects, or through a separate Comparator. In Java8, there is a Stream <T> with which it looks shorter and, I suppose, you called that to be selects. - SomeFire