@Test public void testSplitKeepEmpty() { Assert.assertEquals(1, StringUtil.splitKeepEmpty(";;;;", ".").length); Assert.assertEquals(5, StringUtil.splitKeepEmpty(";;;;", ";").length); Assert.assertEquals(5, StringUtil.splitKeepEmpty("blah;foo;;bar;test", ";").length); Assert.assertEquals(5, StringUtil.splitKeepEmpty("blah;;foo;;;;bar;;test", ";;").length); Assert.assertEquals(5, StringUtil.splitKeepEmpty(";;;;;;;;", ";;").length); }
public static String[] splitKeepEmpty(final String string, final String split) { final String[] result = new String[count(string, split) + 1]; int from, index = -split.length(); for (int i = 0; i < result.length; i++) { from = index + split.length(); index = string.indexOf(split, from); if (index == -1) { index = string.length(); } result[i] = string.substring(from, index); } return result; }
StringUtil { public static String[] splitKeepEmpty(final String string, final String split) { final String[] result = new String[count(string, split) + 1]; int from, index = -split.length(); for (int i = 0; i < result.length; i++) { from = index + split.length(); index = string.indexOf(split, from); if (index == -1) { index = string.length(); } result[i] = string.substring(from, index); } return result; } }
StringUtil { public static String[] splitKeepEmpty(final String string, final String split) { final String[] result = new String[count(string, split) + 1]; int from, index = -split.length(); for (int i = 0; i < result.length; i++) { from = index + split.length(); index = string.indexOf(split, from); if (index == -1) { index = string.length(); } result[i] = string.substring(from, index); } return result; }  }
StringUtil { public static String[] splitKeepEmpty(final String string, final String split) { final String[] result = new String[count(string, split) + 1]; int from, index = -split.length(); for (int i = 0; i < result.length; i++) { from = index + split.length(); index = string.indexOf(split, from); if (index == -1) { index = string.length(); } result[i] = string.substring(from, index); } return result; }  static String toString(final Vector vect); static Vector toVector(final String string); static String toLowerCamelCase(final String originalString); static String joinStrings(final String[] array, final int start); static String joinStrings(final String[] array, final int start, final int end); static String joinStrings(final String joinString, final String[] array, final int start); static String joinStrings(final String joinString, final String[] array, final int start, final int end); static String joinStrings(final String... strings); static String joinStrings(final String joinString, final String... strings); static String getPossibleSeparator(final List<String> strings, final int size); static String[] splitKeepEmpty(final String string, final String split); static int count(final String inString, final String substring); static String prependLines(final String string, final String prefix); }
StringUtil { public static String[] splitKeepEmpty(final String string, final String split) { final String[] result = new String[count(string, split) + 1]; int from, index = -split.length(); for (int i = 0; i < result.length; i++) { from = index + split.length(); index = string.indexOf(split, from); if (index == -1) { index = string.length(); } result[i] = string.substring(from, index); } return result; }  static String toString(final Vector vect); static Vector toVector(final String string); static String toLowerCamelCase(final String originalString); static String joinStrings(final String[] array, final int start); static String joinStrings(final String[] array, final int start, final int end); static String joinStrings(final String joinString, final String[] array, final int start); static String joinStrings(final String joinString, final String[] array, final int start, final int end); static String joinStrings(final String... strings); static String joinStrings(final String joinString, final String... strings); static String getPossibleSeparator(final List<String> strings, final int size); static String[] splitKeepEmpty(final String string, final String split); static int count(final String inString, final String substring); static String prependLines(final String string, final String prefix);  }