Hello. Im stuck on writing Word occurrence in a string. I got some tip(in task notes) to use is compareToIgnoreCase. so I tried something like this:
splitwords = StringCont.split("\\s");
for(int i=0; i<splitwords.length; i++)
{
if(splitwords[1].compareToIgnoreCase(splitwords[i]) == 0)
splitcount++;
}
It is of course just what I can do and probably bad way. When I run the code, I get sometimes out of array exeption and sometimes it runs. What is missing is: go through all words and check them and skip the words which were already counted. I will be happy to get any help with this so can move along and understand how it can be coded. Thank you :)
Edit: It seems I did not explain the problem enough clearly, but I get nice answer about the map object which easily put together what I needed. I did not know about map. So yea, I was trying to find the number of times every given word is found in the string.
tangens: it should mean-take the first word(where first whitespace is) splitwords[1] and compare it to all other words in string splitwords[i] and if it is 0(equals), then count++.
Esko: there indeed are white spaces like in sentence. But I still got this exeption. I dont know why thru.