I am just beginning to tackle some USACO practice problems using Java. However, I've immediately encountered some confusion regarding parsing file input...
The USACO training pages say:
Important: BufferedReader and StringTokenizer are far more efficient than many other schemes for reading input. They can make a huge difference in the efficiency of your program! Use them!
However, the Oracle docs say:
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.
I am finding very mixed opinions on the internet. Some, including the training pages, say that StringTokenizer
should be used because it's faster than String.split()
which is faster than Scanner
(though this answer disagrees). Others say Scanner
or String.split()
should be used because they're simpler to use and because the performance cost from parsing files is negligible.
Which method is the most practical as of now?