ArrayList に含まれる単語の数を計算しようとしています。すべての単語が別の行にある場合にこれを行う方法を知っていますが、次のように一部の単語が同じ行にある場合:
hello there
blah
cats dogs
したがって、すべてのエントリを調べて、現在のエントリに含まれる単語の数をどうにかして調べる必要があると考えています。たとえば、次のようになります。
public int numberOfWords(){
for(int i = 0; i < arraylist.size(); i++) {
int words = 0;
words = words + (number of words on current line);
//words should eventually equal to 5
}
return words;
}
私は正しいと思いますか?