看框架源码的时候,看到了StringTokenizer对象,从来没用过,才发现在截取字符串上StringTokenizer的性能要远远优于split和substring这2个方法
简单demo:
package com.innofarm.text;
import java.util.StringTokenizer;
public class StringTokenizer字符串截取测试 {
public static void main(String[] args) {
String s = "A,B,C,D,E,F,G,H,I,J";
StringTokenizer tokenizer = new StringTokenizer(s, ",");
while (tokenizer.hasMoreTokens()) {
String levelString = tokenizer.nextToken().trim();
System.out.println(levelString);
}
}
}
深入学习:
subString、split、stringTokenizer三种截取字符串方法的性能比较