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
沒有留言:
張貼留言