My input file will be look like this
போதும் 1 போதும் 2 போதும் 3 போதும் 4 போதும் 5 போதும் 6 போதும் 7 போதும் 8 போதும开发者_JS百科் 9 போதும் 10 போதும் 11 போட்டால் 1 போட்டால் 2 பொன் 1 பொன் 2 பொன் 3 பொன் 4 பொன் 5
and my output want to be as
போதும் 11 போட்டால் 2 பொன் 5
How to select the each word with its maximum value using java program. Pls suggest me any ideas. Thanks in advance.
Something along these lines:
- Create a
HashMap<String, Integer>
- For each line in your input:
- Split it into the word and number, and parse the number part (as Matthew comments below, using
Scanner
can help with this part) - See if there's anything in your map for that word
- If there isn't, use
map.put(word, value)
- If there is, compare the current value with the new one, and replace the current value if the new one is higher
- If there isn't, use
- Split it into the word and number, and parse the number part (as Matthew comments below, using
- When you've read everything in the file, your map will contain (word / maximum value) pairs. You can iterate over the map's entries to get at everything you need.
Check this program: http://leepoint.net/notes-java/data/collections/maps/ex-wordfreq.html It could be helpful to you.
精彩评论