@Test void split() { List<String>[] lists = Lists.split(LIST, "b"); Assertions.assertEquals(2, lists.length); Assertions.assertAll( () -> Assertions.assertEquals(Collections.singletonList("a"), lists[0]), () -> Assertions.assertEquals(Collections.singletonList("c"), lists[1]) ); }
public static <T> List<T>[] split(List<T> list, T delimiter) { List<List<T>> elements = new ArrayList<>(); int previousIndex = -1; for (int index = 0; index < list.size(); index++) { if (!list.get(index).equals(delimiter)) { continue; } elements.add(list.subList(++previousIndex, index)); previousIndex = index; } if (previousIndex > -1) { elements.add(subList(list, ++previousIndex)); } if (elements.isEmpty()) { elements.add(list); } return elements.toArray(new List[0]); }
Lists { public static <T> List<T>[] split(List<T> list, T delimiter) { List<List<T>> elements = new ArrayList<>(); int previousIndex = -1; for (int index = 0; index < list.size(); index++) { if (!list.get(index).equals(delimiter)) { continue; } elements.add(list.subList(++previousIndex, index)); previousIndex = index; } if (previousIndex > -1) { elements.add(subList(list, ++previousIndex)); } if (elements.isEmpty()) { elements.add(list); } return elements.toArray(new List[0]); } }
Lists { public static <T> List<T>[] split(List<T> list, T delimiter) { List<List<T>> elements = new ArrayList<>(); int previousIndex = -1; for (int index = 0; index < list.size(); index++) { if (!list.get(index).equals(delimiter)) { continue; } elements.add(list.subList(++previousIndex, index)); previousIndex = index; } if (previousIndex > -1) { elements.add(subList(list, ++previousIndex)); } if (elements.isEmpty()) { elements.add(list); } return elements.toArray(new List[0]); }  }
Lists { public static <T> List<T>[] split(List<T> list, T delimiter) { List<List<T>> elements = new ArrayList<>(); int previousIndex = -1; for (int index = 0; index < list.size(); index++) { if (!list.get(index).equals(delimiter)) { continue; } elements.add(list.subList(++previousIndex, index)); previousIndex = index; } if (previousIndex > -1) { elements.add(subList(list, ++previousIndex)); } if (elements.isEmpty()) { elements.add(list); } return elements.toArray(new List[0]); }  static T add(Collection<T> list, T element); static List<T> subList(List<T> list, int startIndex); static ArrayList<T> subList(List<T> list, int startIndex, int endIndex); @SafeVarargs static void sort(Comparator<T> comparator, List<? extends T>... collections); static List<T> reverse(List<T> list); static List<T>[] split(List<T> list, T delimiter); @SafeVarargs static List<T> mutableOf(T... elements); static T get(List<T> list, int index); }
Lists { public static <T> List<T>[] split(List<T> list, T delimiter) { List<List<T>> elements = new ArrayList<>(); int previousIndex = -1; for (int index = 0; index < list.size(); index++) { if (!list.get(index).equals(delimiter)) { continue; } elements.add(list.subList(++previousIndex, index)); previousIndex = index; } if (previousIndex > -1) { elements.add(subList(list, ++previousIndex)); } if (elements.isEmpty()) { elements.add(list); } return elements.toArray(new List[0]); }  static T add(Collection<T> list, T element); static List<T> subList(List<T> list, int startIndex); static ArrayList<T> subList(List<T> list, int startIndex, int endIndex); @SafeVarargs static void sort(Comparator<T> comparator, List<? extends T>... collections); static List<T> reverse(List<T> list); static List<T>[] split(List<T> list, T delimiter); @SafeVarargs static List<T> mutableOf(T... elements); static T get(List<T> list, int index);  }