Counting words is best done by using the StringTokenizer class..
if we compare stringtokenizer and the split method of java.util.regex on stability issues.. can anyone elaborate on this one?
actually i am new to java.. thats why i joined this forum to learn more much from you guys. thanks alot..
did you not read the other replies that advised you not to use StringTokenizer and to use String.split or Scanner instead?Quote:
Is there no other way around this. As I havent learnt how to use the StringTokenizer class
If you know how many words are needed then you can use an array. If the number of words is unknown and to make it more flexible you can use a List.
That line of code is unnecessary as the Scanner.next method will return a String with no spaces in it.Code:
line = line.replace(" ", "");