开发者

Java Text Reader

开发者 https://www.devze.com 2023-04-08 13:26 出处:网络
I want to make a program that read the inputed text and parse every word and store it in a data structure, so i can later have some statistics about that (frequency of words, most common word etc).

I want to make a program that read the inputed text and parse every word and store it in a data structure, so i can later have some statistics about that (frequency of words, most common word etc).

I need guidance about two things:

a. best approach for my "parse function", which will divide the text in terms

b. best approach for 开发者_Go百科data structure choice, in what concerns complexity, access times and best suitable for the case.


a) best approach for my "parse function"

Use a Scanner it has nice functions for next (word) etc.

b) best approach for datastruture choice

A map from word to a statistics object: Map<String, WordStatistics>.


Depending on the other stats you need, it sounds like you want to use a Map<String, Integer>. Then for each key (the word you read in) you can store how many times you read it in. The rest sounds like homework...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号