Java: StringTokenizer VS Split

Categories: Java; Tagged with: ; @ April 17th, 2009 21:52

两个的差别:

	public static void main(String[] args) {
		String str = "1,2,,3";
		String delimiter = ",";
		StringTokenizer tokens = new StringTokenizer(str, delimiter);
		while(tokens.hasMoreTokens()) {
			System.out.println(tokens.nextToken());
		}

		System.out.println("---------无聊的分割线---------");
		String[] result = str.split(delimiter);
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i]);
		}
	}

输出:

1

2

3

———无聊的分割线———

1

2

3

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.