ListHelper { public static List<String> parseString(String serializedString, char separatorChar) { List<String> results = null; if (serializedString != null) { serializedString = serializedString.trim(); results = new ArrayList<String>(); int start = 0; int pos; int length = serializedString.length(); while ((pos = serializedString.indexOf(separatorChar, start)) >= 0) { add(serializedString.substring(start, pos), results); start = Math.min(pos + 1, length); } if (start < length) { add(serializedString.substring(start), results); } } return results; }  static List<String> parseString(String serializedString, char separatorChar);  }
@Test public void testParseString() { assertEqualsList(ListHelper.parseString("", '|')); assertEqualsList(ListHelper.parseString("a", '|'), "a"); assertEqualsList(ListHelper.parseString("a| b", '|'), "a", "b"); assertEqualsList(ListHelper.parseString("a| b|", '|'), "a", "b"); assertEqualsList(ListHelper.parseString("a| b| ", '|'), "a", "b"); assertEqualsList(ListHelper.parseString("|a| b| ", '|'), "a", "b"); assertEqualsList(ListHelper.parseString("|a| b|| ", '|'), "a", "b"); }