File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 175
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: 175
problem solved...sorry ....My bad
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7696
    
  20

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
 
jQuery in Action, 2nd edition
 
subject: Program to find repeated words