Bootstrap

StringTokenizer的使用

今天阅读jmeter源码,StringTokenizer,用来分割字符串的工具类,其构造函数

1. StringTokenizer(String str) 
构造一个用来解析str的StringTokenizer对象。java默认的分隔符是空格、制表符(\t)、换行符(\n)、回车符(\r)

2. StringTokenizer(String str, String delim)
构造一个用来解析str的StringTokenizer对象,并提供一个指定的分隔符

3. StringTokenizer(String str, String delim, boolean returnDelims)
构造一个用来解析str的StringTokenizer对象,并提供一个指定的分隔符,同时,指定是否返回分隔符。

且看代码

public class Test {

    public static void main(String[] args) {
        String initiaClasspath = System.getProperty("java.class.path");
        StringTokenizer st = new StringTokenizer(initiaClasspath, File.pathSeparator, false);
        System.out.println( "Token Total: " + st.countTokens() );
        while( st.hasMoreElements() ){
            System.out.println(st.nextToken());
        }
    }
}

打印结果如下

Token Total: 27
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\charsets.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\deploy.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\access-bridge-32.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\cldrdata.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\dnsns.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\jaccess.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\localedata.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\nashorn.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\sunec.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext\zipfs.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\javaws.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\jce.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\jfr.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\jfxswt.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\jsse.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\management-agent.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\plugin.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\resources.jar
C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\rt.jar
E:\tmp\testMS\out\production\testMS
E:\app\software\apache-jmeter-5.1.1\lib\ext\mobileinterface-common-1.1.jar
E:\app\software\apache-jmeter-5.1.1\lib\ext\mobileinterface-encryption-1.1.jar
E:\Program Files\JetBrains\IntelliJ IDEA 2017.2.4\lib\idea_rt.jar

 

;