com.github.naviit.libs.common.util.StringSplitter Maven / Gradle / Ivy
package com.github.naviit.libs.common.util;
import java.util.ArrayList;
import java.util.List;
public class StringSplitter {
public static List toListBySpace(String value) {
if (value == null) return new ArrayList(0);
List temp = new ArrayList((value.length() / 2) + 1);
int start = 0;
int i = 1;
while (i < value.length()) {
char c = value.charAt(i);
if (Character.isWhitespace(c) || Character.isSpaceChar(c)) {
String element = value.substring(start, i);
if (!element.isEmpty()) temp.add(element);
start = i + 1;
i++;
continue;
}
i++;
}
if (start < value.length()) {
String element = value.substring(start);
if (!element.isEmpty()) temp.add(element);
}
return temp;
}
public static String[] toArrayBySpace(String value){
List list = toListBySpace(value);
return list.toArray(new String[list.size()]);
}
public static void main(String[] args) {
List test = toListBySpace("Tung is hand Some");
System.out.println(test);
}
}