I have an issue solving a problem. I have to add ONLY words into a treeset (and output the size of treeset) using bufferedReader but the problem is I cannot pass the compilator speed test limit. The text contains only letters and whitespaces (it can be an empty line). I have to find out a new solution but seems not this :
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
Set<String> text = new TreeSet<String>();
String words[], line;
while ((line = read.readLine()) != null) {
words = line.split("\\s+");
for (int i = 0; i < words.length && words[0].length() > 0; i++) {
text.add(words[i]);
}
}
System.out.println(text.size());
Is there any other "split" method to use so the compiler use less "time-thinking"?