aspose file tools*
The moose likes Beginning Java and the fly likes Program to find repeated words Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Program to find repeated words" Watch "Program to find repeated words" New topic
Author

Program to find repeated words

Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 178
Hi everybody
I have made a program which finds the number of occurrence of the words. It is as follows :Output is coming {This=0, is=1, me=1, tarun=1, ohri=1}
Why is it coming wrong ? Any Guess ??
Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 178
problem solved...sorry ....My bad
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8206
    
  23

Tarun Oohri wrote:Why is it coming wrong ? Any Guess ??

Yes. Integer is an immutable class (ie, you can't change it), so you have to replace it in your Map every time you get a repeated word.

You might find things easier if you use AtomicInteger instead, because you can update those.

HIH

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
 
subject: Program to find repeated words