Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference and usage of StringTokenizer and String.split()  RSS feed

 
Nidheesh Krishna
Ranch Hand
Posts: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the difference between StringTokenizer and String.split()? Which is more faster? which is suitable to operate with large files?
 
Dave Tolls
Rancher
Posts: 2911
35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could just read the API for StringTokenizer.

"
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.
"

 
Campbell Ritchie
Marshal
Posts: 55681
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As DT says, tokenizer has not had a usage for fifteen years. You should not worry about which is faster at this stage. Neither is suitable for use with a file because a file is not in the form of a String. Only when you read a file do you get Strings and the file reading classes all produce multiple Strings representing lines. Some means of reading from text files (e.g. Scanner can translate the text directly into other datatypes (e.g. ints), which would make splitting the String unnecessary.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!