I'm looking for an efficient way to obtain a list of String tokens extracted from multiple Strings (e.g. with a whitespace separator).
Example:
String s1 = "My mom cook everyday";
String s2 = "I eat everyday";
String s3 = "Am I fat?";
LinkedList<String> tokens = new LinkedList<String>();
//any code to efficiently get the tokens
//final result is tokens make of a list of the following tokens:
//"My", "mom", "cook", "everyday", "I", "eat", "everyday", "Am", "I", "fat?".
Now
- I'm not sure that
LinkedList
is the most effective collection class to be used (Apache Commons, Guava, may they help?)! - I was going to use
StringUtils
from Apache Commons, but thesplit
method returns an array! So, I should extract with a for cycle the Strings from the array of String objects returned by split. Is that efficient: I don't know,split
creates an array! - I read about
Splitter
from Guava, but this post states thatStringUtils
is better in practice. - What about
Scanner
fromJava.util
. It seems to not allocate any additional data structures. Isn't it?
Please, draw the most efficient Java solution, even by using additional widely used library, like Guava and Apache Commons.