StringUtils { public static List<String> split(String s, char delimiter, boolean skipBackSlash) { int pos = s.indexOf(delimiter); if (pos == -1) { return Collections.singletonList(s); } List<String> list = new ArrayList(); int startPos = 0; int searchPos = 0; while (pos != -1) { if (skipBackSlash && pos > 0 && s.charAt(pos - 1) == '\\') { s = s.substring(0, pos - 1) + s.substring(pos); searchPos = pos; } else { String temp = s.substring(startPos, pos); if (!EMPTY.equals(temp)) { list.add(temp); } startPos = pos + 1; searchPos = startPos; } pos = s.indexOf(delimiter, searchPos); } if (startPos != s.length()) { String temp = s.substring(startPos); if (!EMPTY.equals(temp)) { list.add(temp); } } return list; } private  StringUtils(); static Pair pair(String left, String right); static String truncate(String s, int length, boolean addDots); static String trimToEmpty(String s); static String trimToNull(String s); static String repeat(char c, int count); static String join(Object[] a, char delimiter); static String join(Collection<String> c, char delimiter); static List<String> split(String s, char delimiter, boolean skipBackSlash); static boolean isBlank(String s); static String toIdString(String name); static StringUtils.Pair splitByFirstLineFeed(String text); static List<String> toStringLines(String text); static int countLineFeeds(String text); static int wrappedLinesEstimate(String text, int colWidth); static boolean isJavaScriptFunction(String text); static String fixJavaScriptFunction(String text);  }
@Test public void testSplit() { List<String> list = StringUtils.split("", '/', false); assertEquals(1, list.size()); assertEquals("", list.get(0)); list = StringUtils.split(" assertEquals(0, list.size()); list = StringUtils.split("foo", '/', false); assertEquals(1, list.size()); assertEquals("foo", list.get(0)); list = StringUtils.split("foo/", '/', false); assertEquals(1, list.size()); assertEquals("foo", list.get(0)); list = StringUtils.split("/foo", '/', false); assertEquals(1, list.size()); assertEquals("foo", list.get(0)); list = StringUtils.split("/foo/bar", '/', false); assertEquals(2, list.size()); assertEquals("foo", list.get(0)); assertEquals("bar", list.get(1)); list = StringUtils.split("|pi\\|pe|blah|", '|', true); assertEquals(2, list.size()); assertEquals("pi|pe", list.get(0)); assertEquals("blah", list.get(1)); }