Did some testing on StringTokenizer and StringUtils.splitByWholeSeparator. Here is the code.
public class StringTokenizerTest {
private static String str = "\"abc\",\"test\",\"abc,te\"-st\"";
public static void main(String[] args) {
String delimeter = "\",\"";
StringTokenizer st = new StringTokenizer(str,delimeter);
while(st.hasMoreTokens()){
System.out.println(st.nextToken());
}
System.out.println("");
String[] items = StringUtils.splitByWholeSeparator(str, delimeter);
for(String item : items){
System.out.println(item);
}
}
}
Here is the result
abc
test
abc
te
-st
"abc
test
abc,te"-st"
We can see StringTokenizer use each character in the delimeter as the delimeter.
No comments:
Post a Comment