import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public class Main {
public static void main
(String args
[]) { List
<String
> list
= List.
of("12-2014",
"11-2012",
"5-2014",
"8-2012"); DateTimeFormatter dtf
= DateTimeFormatter.
ofPattern("M-uuuu",
Locale.
ENGLISH); List<String> sorted =
list.stream()
.map(s -> YearMonth.parse(s, dtf))
.map(ym -> dtf.format(ym))
.collect(Collectors.toList());
// Display the list
}
}
aW1wb3J0IGphdmEudGltZS5ZZWFyTW9udGg7CmltcG9ydCBqYXZhLnRpbWUuZm9ybWF0LkRhdGVUaW1lRm9ybWF0dGVyOwppbXBvcnQgamF2YS51dGlsLkNvbXBhcmF0b3I7CmltcG9ydCBqYXZhLnV0aWwuTGlzdDsKaW1wb3J0IGphdmEudXRpbC5Mb2NhbGU7CmltcG9ydCBqYXZhLnV0aWwuc3RyZWFtLkNvbGxlY3RvcnM7CgpwdWJsaWMgY2xhc3MgTWFpbiB7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmcgYXJnc1tdKSB7CgkJTGlzdDxTdHJpbmc+IGxpc3QgPSBMaXN0Lm9mKCIxMi0yMDE0IiwgIjExLTIwMTIiLCAiNS0yMDE0IiwgIjgtMjAxMiIpOwoJCURhdGVUaW1lRm9ybWF0dGVyIGR0ZiA9IERhdGVUaW1lRm9ybWF0dGVyLm9mUGF0dGVybigiTS11dXV1IiwgTG9jYWxlLkVOR0xJU0gpOwoJCUxpc3Q8U3RyaW5nPiBzb3J0ZWQgPSAKCQkJCWxpc3Quc3RyZWFtKCkKCQkJCQkubWFwKHMgLT4gWWVhck1vbnRoLnBhcnNlKHMsIGR0ZikpCgkJCQkJLnNvcnRlZChDb21wYXJhdG9yLnJldmVyc2VPcmRlcigpKQoJCQkJCS5tYXAoeW0gLT4gZHRmLmZvcm1hdCh5bSkpCgkJCQkJLmNvbGxlY3QoQ29sbGVjdG9ycy50b0xpc3QoKSk7CgoJCS8vIERpc3BsYXkgdGhlIGxpc3QKCQlTeXN0ZW0ub3V0LnByaW50bG4oc29ydGVkKTsKCX0KfQ==