@Test public void testSplitWithCommaOrSemicolon() throws Exception { String[] s = StringUtils.splitWithCommaOrSemicolon(null); Assert.assertTrue(CommonUtils.isEmpty(s)); s = StringUtils.splitWithCommaOrSemicolon(""); Assert.assertTrue(CommonUtils.isEmpty(s)); s = StringUtils.splitWithCommaOrSemicolon("1"); Assert.assertNotNull(s); Assert.assertEquals(s.length, 1); s = StringUtils.splitWithCommaOrSemicolon("1,"); Assert.assertNotNull(s); Assert.assertEquals(s.length, 1); s = StringUtils.splitWithCommaOrSemicolon(" 1,"); Assert.assertNotNull(s); Assert.assertEquals(s.length, 1); s = StringUtils.splitWithCommaOrSemicolon(" 1,2"); Assert.assertNotNull(s); Assert.assertEquals(s.length, 2); s = StringUtils.splitWithCommaOrSemicolon(" 1;2"); Assert.assertNotNull(s); Assert.assertEquals(s.length, 2); }
public static String[] splitWithCommaOrSemicolon(String src) { if (isEmpty(src)) { return StringUtils.EMPTY_STRING_ARRAY; } String[] ss = split(src.replace(',', ';'), ";"); List<String> list = new ArrayList<String>(); for (String s : ss) { if (!isBlank(s)) { list.add(s.trim()); } } return list.toArray(new String[list.size()]); }
StringUtils { public static String[] splitWithCommaOrSemicolon(String src) { if (isEmpty(src)) { return StringUtils.EMPTY_STRING_ARRAY; } String[] ss = split(src.replace(',', ';'), ";"); List<String> list = new ArrayList<String>(); for (String s : ss) { if (!isBlank(s)) { list.add(s.trim()); } } return list.toArray(new String[list.size()]); } }
StringUtils { public static String[] splitWithCommaOrSemicolon(String src) { if (isEmpty(src)) { return StringUtils.EMPTY_STRING_ARRAY; } String[] ss = split(src.replace(',', ';'), ";"); List<String> list = new ArrayList<String>(); for (String s : ss) { if (!isBlank(s)) { list.add(s.trim()); } } return list.toArray(new String[list.size()]); }  }
StringUtils { public static String[] splitWithCommaOrSemicolon(String src) { if (isEmpty(src)) { return StringUtils.EMPTY_STRING_ARRAY; } String[] ss = split(src.replace(',', ';'), ";"); List<String> list = new ArrayList<String>(); for (String s : ss) { if (!isBlank(s)) { list.add(s.trim()); } } return list.toArray(new String[list.size()]); }  static boolean isEmpty(CharSequence cs); static boolean isNotEmpty(CharSequence cs); static boolean isBlank(CharSequence cs); static boolean isNotBlank(CharSequence cs); static String trim(String str); static String trimToNull(String str); static String trimToEmpty(String str); static String toString(byte[] bytes, String charsetName); static String defaultString(final Object str); static String toString(Object o, String defaultVal); static String toString(Object o); static String objectsToString(Object[] args); static boolean equals(CharSequence s1, CharSequence s2); static String[] split(String src, String separator); static String[] splitWithCommaOrSemicolon(String src); static String join(String[] strings, String separator); static String joinWithComma(String... strings); static String substringAfter(String str, String separator); static String substringBefore(String str, String separator); }
StringUtils { public static String[] splitWithCommaOrSemicolon(String src) { if (isEmpty(src)) { return StringUtils.EMPTY_STRING_ARRAY; } String[] ss = split(src.replace(',', ';'), ";"); List<String> list = new ArrayList<String>(); for (String s : ss) { if (!isBlank(s)) { list.add(s.trim()); } } return list.toArray(new String[list.size()]); }  static boolean isEmpty(CharSequence cs); static boolean isNotEmpty(CharSequence cs); static boolean isBlank(CharSequence cs); static boolean isNotBlank(CharSequence cs); static String trim(String str); static String trimToNull(String str); static String trimToEmpty(String str); static String toString(byte[] bytes, String charsetName); static String defaultString(final Object str); static String toString(Object o, String defaultVal); static String toString(Object o); static String objectsToString(Object[] args); static boolean equals(CharSequence s1, CharSequence s2); static String[] split(String src, String separator); static String[] splitWithCommaOrSemicolon(String src); static String join(String[] strings, String separator); static String joinWithComma(String... strings); static String substringAfter(String str, String separator); static String substringBefore(String str, String separator); static final String EMPTY; static final String CONTEXT_SEP; static final String ALL; static final String DEFAULT; static final String TRUE; static final String FALSE; static final String NULL; static final String[] EMPTY_STRING_ARRAY; }