P28 { public static <T> List<List<T>> lsort(List<List<T>> list) { list.sort((xs1, xs2) -> xs1.size() - xs2.size()); return list; }  static List<List<T>> lsort(List<List<T>> list); static List<List<String>> lfsort(List<List<String>> list); static List<List<String>> lfsort1(List<List<String>> list);  }
@Test public void shouldSortByElementLength() throws Exception { List<List<String>> input = Arrays.asList(Arrays.asList("a", "b", "c"), Arrays.asList("d", "e"), Arrays.asList("f", "g", "h"), Arrays.asList("d", "e"), Arrays.asList("i", "j", "k"), Arrays.asList("m", "n"), Arrays.asList("o")); List<List<String>> result = P28.lsort(input); assertThat(result, is(equalTo(Arrays.asList(Arrays.asList("o"), Arrays.asList("d", "e"), Arrays.asList("d", "e"), Arrays.asList("m", "n"), Arrays.asList("a", "b", "c"), Arrays.asList("f", "g", "h"), Arrays.asList("i", "j", "k"))))); }