Tokenize a string: Difference between revisions
Content deleted Content added
Added 2 tokenization technique with java |
m →[[Java]]: remove unnessary tabbing |
||
Line 9:
There is multiple way to tokenized a string in Java. The first with a split the String into an array of String, and the other way to give a Enumerator. The second way given here will skip any empty token. So if two commas are given in line, there will be an empty string in the array given by the split function but no empty string with the StringTokenizer object.
//First way
}
▲ String word[] = toTokenize.split(",");
▲ for(int i=0; i<word.length; i++) {
}
▲ StringTokenizer tokenizer = new StringTokenizer(toTokenize, ",");
▲ while(tokenizer.hasMoreTokens()) {
▲ System.out.println(tokenizer.nextToken());
==[[JavaScript]]==
|