比如有一篇txt文本,内容如下:April
April is the fourth month of the year with 30 days. The name April comes from that Latin word
April in poetry.
Poets use "April" to mean the end of winter. For example: "April showers bring May flowers."Autonomous communities of Spain
Spain has fifty smaller parts called provinces. In 1978 these parts came together, making the autonomous communities.
Before then, some of these provinces were together but were broken. The groups that were has two cities on the north coast of Africa: Ceuta and Melilla. They are called "autonomous cities".也就是一个标题,下面几段文字。这就是一个段落。一个空行,下面是新的标题+文字。现在要读取这个txt,然后计算每个单词在,比如“good”在文中的:1)一共出现在多少段落中。2)出现该单词的段落的标题是什么,以及在此段落中出现了几次。 讲结果存入TreeMap中。 未来可以输入一个单词,比如“good”,就能得出{标题,次数}这样的结果。 java单词
April is the fourth month of the year with 30 days. The name April comes from that Latin word
April in poetry.
Poets use "April" to mean the end of winter. For example: "April showers bring May flowers."Autonomous communities of Spain
Spain has fifty smaller parts called provinces. In 1978 these parts came together, making the autonomous communities.
Before then, some of these provinces were together but were broken. The groups that were has two cities on the north coast of Africa: Ceuta and Melilla. They are called "autonomous cities".也就是一个标题,下面几段文字。这就是一个段落。一个空行,下面是新的标题+文字。现在要读取这个txt,然后计算每个单词在,比如“good”在文中的:1)一共出现在多少段落中。2)出现该单词的段落的标题是什么,以及在此段落中出现了几次。 讲结果存入TreeMap中。 未来可以输入一个单词,比如“good”,就能得出{标题,次数}这样的结果。 java单词
就是一个简单的查找的问题。
1、吧文章按空行分开 没一部分的第一行为标题 剩余的为内容
2、将内容按空格 存入list中 遍历list 如果为新单词 存入另一个list中 不是新单词 则将个数+1