The 2020-10-28
The 2020-10-29
The 2020-10-30
The 2020-11-02
The 2020-11-03
The 2020-11-04
The 2020-11-05
The 2020-11-06
The 2020-11-09
The 2020-11-10
The 2020-11-11
The 2020-11-12
The 2020-11-13
The 2020-11-16
The 2020-11-17
The 2020-11-18
The 2020-11-19
The 2020-11-20
The 2020-11-23
The 2020-11-24
The 2020-11-25
The 2020-11-26
The 2020-11-27
The 2020-11-30
The 2020-12-01
The 2020-12-02
With the algorithm to find the maximum value of each month, returns a new list
The 2020-10-30
The 2020-11-30
2020-12-02
CodePudding user response:
For examplepublic class Sample {
Public static void main (String [] args) {
ListList=new ArrayList<> (arrays.aslist (new String [] {
"2020-10-01", "2020-10-30", "2020-11-01", "2020-11-30", "2020-12-01", "2020-12-02"
}));
ListResult=list. Stream (). Collect (Collectors. GroupingBy (e - & gt; E.s ubstring (0, 7))). EntrySet () stream (). The map (e - & gt; {
Return the um participant etValue (). The stream (). Max ((s1, s2) - & gt; S1.com pareTo (s2)). The get ();
}). Collect (Collectors. ToList ());
System. The out. Println (result);
}
}
CodePudding user response:
If the data is not more than 100000, in the database to solve,CodePudding user response: