將一個字串分為數個token。
第一個引數為需split部分,第二個引數為該token的開始值。
public class StringTokenizing { public static void main(String args[]){ String text = "To be or not to be, that is the question"; String delimits = "[, .]"; String[] tokens = text.split(delimits, 0); String[] tokens1 = text.split(delimits, 5); System.out.println("Num of tokens: " + tokens.length); for(String token:tokens){ System.out.println(token); } System.out.println("Num of tokens: " + tokens1.length); for(String token:tokens1){ System.out.println(token); } } }
.jpg)