有一个集合可以容纳一个字符串和一个具有重复值的整数吗?
我有一个文本,我将根据每个短语的单词数进行一些过滤。
我正在考虑使用 Map,在键中放置短语、int 值、单词的数量,在 Map 上迭代并删除比先前指定的值较小的行。
- 有一个地图,我可以在其中保存重复的条目(短语和数量)?
- 我可以按照放置元素的顺序从地图中检索吗?这是因为是文本,所以短语的顺序很重要。
示例
原始文本
我的名字是雷纳托 | 4
今天是星期二 | 3
我住在巴西 | 4
我的名字是雷纳托 | 4
20年| 2
StackOverflow 是一个非常棒的网站 | 5
过滤删除少于 4 个单词的短语
最终文本
我的名字是雷纳托
我住在巴西
我的名字是雷纳托
StackOverflow 是一个很棒的网站
I have an text and I will do some filtering based in the number of the words of each phrase.
I was thinking in using a Map, in the key I put the phrase, int the value, the quantity of the words, iterate on the Map and remove the lines that have minor value than something previous specified.
- There is a map where can I hold repeated entries (the phrase and the quantity)?
- Can I retrieve from the map in the order I have placed the elements? This is because is a text, so the order of the phrases is important.
EXAMPLE
Original Text
My name is Renato | 4
Today is Tuesday | 3
I live in Brazil | 4
My name is Renato | 4
20 years | 2
StackOverflow is a fantastic website | 5
Filtering removing phrases with less than 4 words
Final Text
My name is Renato
I live in Brazil
My name is Renato
StackOverflow is a fantastic website
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么没有
LinkedHashMap
Why not have
LinkedHashMap
我认为你可以使用LinkedHashMap。它保留你输入的顺序
然后你可以添加并执行你的操作。
I think you can go for LinkedHashMap.It preserves the order in which you entered
Then you can add and perform your operations.
好吧,地图界面看起来就像您所需要的。具体的实现应该是LinkedHashMap,因为您希望能够按照插入的顺序检索元素。
因此,您只需
添加行,使用 for (Stringphrase : myMap.keys()) 迭代它们,然后对它们执行您想要的操作!
Well the Map interface looks like what you'd need. The specific implementation should be LinkedHashMap, because you want to be able to retrieve the elements in the order you inserted them.
So you will have
then just add the lines, iterate over them with a for (String phrase : myMap.keys()) and do what you want with them!