Hello there,
It's been a little while since I used Java and I'm trying to brush up on my skills, I have the following problem.
I have a string in the SimpleCharacterReader class which is like the following:
"Word word, wOrd word word worD\n" + "a few more words, wordS, yes more words\n" +
SimpleCharacterReader has a method called getNextChar() which does what you'd expect, returns the next character in the sequence. What I am trying to do is create a list of word frequency so for the above
word - 6
words - 3
etc etc
Now currently I have the string being read as follows:
CharacterReader characterReader = new SimpleCharacterReader(); StringBuilder string = new StringBuilder(); try{ while(true){ string.append(characterReader.getNextChar()); } } catch(EOFException e) { try{characterReader.close();} catch(IOException ignore){} } Scanner sc = new Scanner(string.toString());
The issue I have with this, is while it works for my little example, I want it to be able to count the words as it reads them, rather than creating a full string then counting. Are there any clean ways of doing this or do I have to just brute force it, add the characters until a delimiter is detected then calling that a word and putting it in the table?
Sorry if that sounds a bit silly.