@Test public void shouldSplit() { assertThat(Strings.split("c,s,v")).contains("c", "s", "v"); assertThat(Strings.split("c,s,v,")).contains("c", "s", "v"); assertThat(Strings.split(" , csv , x, y ")).contains("csv", "x", "y"); assertThat(Strings.split(",,,")).isEmpty(); }
public static List<String> split(String string) { List<String> list = new ArrayList<String>(); int lastFoundIndex = -1; int nextFoundIndex; while ((nextFoundIndex = string.indexOf(',', lastFoundIndex + 1)) != -1) { String value = string.substring(lastFoundIndex + 1, nextFoundIndex).trim(); if (!value.isEmpty()) { list.add(value); } lastFoundIndex = nextFoundIndex; } String value = string.substring(lastFoundIndex + 1).trim(); if (!value.isEmpty()) { list.add(value); } return list; }
Strings { public static List<String> split(String string) { List<String> list = new ArrayList<String>(); int lastFoundIndex = -1; int nextFoundIndex; while ((nextFoundIndex = string.indexOf(',', lastFoundIndex + 1)) != -1) { String value = string.substring(lastFoundIndex + 1, nextFoundIndex).trim(); if (!value.isEmpty()) { list.add(value); } lastFoundIndex = nextFoundIndex; } String value = string.substring(lastFoundIndex + 1).trim(); if (!value.isEmpty()) { list.add(value); } return list; } }
Strings { public static List<String> split(String string) { List<String> list = new ArrayList<String>(); int lastFoundIndex = -1; int nextFoundIndex; while ((nextFoundIndex = string.indexOf(',', lastFoundIndex + 1)) != -1) { String value = string.substring(lastFoundIndex + 1, nextFoundIndex).trim(); if (!value.isEmpty()) { list.add(value); } lastFoundIndex = nextFoundIndex; } String value = string.substring(lastFoundIndex + 1).trim(); if (!value.isEmpty()) { list.add(value); } return list; } private  Strings(); }
Strings { public static List<String> split(String string) { List<String> list = new ArrayList<String>(); int lastFoundIndex = -1; int nextFoundIndex; while ((nextFoundIndex = string.indexOf(',', lastFoundIndex + 1)) != -1) { String value = string.substring(lastFoundIndex + 1, nextFoundIndex).trim(); if (!value.isEmpty()) { list.add(value); } lastFoundIndex = nextFoundIndex; } String value = string.substring(lastFoundIndex + 1).trim(); if (!value.isEmpty()) { list.add(value); } return list; } private  Strings(); static String nullToEmpty(@Nullable String string); static List<String> split(String string); }
Strings { public static List<String> split(String string) { List<String> list = new ArrayList<String>(); int lastFoundIndex = -1; int nextFoundIndex; while ((nextFoundIndex = string.indexOf(',', lastFoundIndex + 1)) != -1) { String value = string.substring(lastFoundIndex + 1, nextFoundIndex).trim(); if (!value.isEmpty()) { list.add(value); } lastFoundIndex = nextFoundIndex; } String value = string.substring(lastFoundIndex + 1).trim(); if (!value.isEmpty()) { list.add(value); } return list; } private  Strings(); static String nullToEmpty(@Nullable String string); static List<String> split(String string);  }