如何在Java中实现复杂字符串的集合(列表,映射?)? [英] How to implement a collection (list, map?) of complicated strings in Java?
问题描述
问题 - 我有类似以下条目,其中1000条:
Problem -- I have something like the following entries, 1000 of them:
args1=msg args2=flow args3=content args4=depth args6=within ==> args5=content
args1=msg args2=flow args3=content args4=depth args6=within args7=distance ==> args5=content
args1=msg args2=flow args3=content args6=within ==> args5=content
args1=msg args2=flow args3=content args6=within args7=distance ==> args5=content
args1=msg args2=flow args3=flow ==> args4=flowbits
args1=msg args2=flow args3=flow args5=content ==> args4=flowbits
args1=msg args2=flow args3=flow args6=depth ==> args4=flowbits
args1=msg args2=flow args3=flow args6=depth ==> args5=content
args1=msg args2=flow args4=depth ==> args3=content
args1=msg args2=flow args4=depth args5=content ==> args3=content
args1=msg args2=flow args4=depth args5=content args6=within ==> args3=content
args1=msg args2=flow args4=depth args5=content args6=within args7=distance ==> args3=content
我在做一些建议的方法。说, args1 = msg args2 = flow args3 = flow ==> args4 = flowbits
I'm doing some sort of suggestion method. Say, args1=msg args2=flow args3=flow ==> args4=flowbits
如果句子包含msg,flow和另一个流,那么我应该返回flowbits的建议。
If the sentence contains msg, flow, and another flow, then I should return the suggestion of flowbits.
我该怎么办呢?我知道我应该扫描(每当一个字符被压在textarea)一个列表或数组的匹配和返回结果,但是,1000条目,我应该如何实现?
How can I go around doing it? I know I should scan (whenever a character is pressed on the textarea) a list or array for a match and return the result, but, 1000 entries, how should I implement it?
我在想HashMap,但我可以这样做吗?
I'm thinking of HashMap, but can I do something like this?
<msg,flow,flow,flowbits>
<"msg,flow,flow","flowbits">
此外,在一个句子中的参数可能不是有序的,所以假设它的流,流,msg然后我不能匹配任何在HashMap中的关键是msg ,flow,flow。
Also, in a sentence the arguments might not be in order, so assuming that it's flow,flow,msg then I can't match anything in the HashMap as the key is "msg,flow,flow".
在这种情况下该怎么办?请帮忙。感谢一百万!
What should I do in this case? Please help. Thanks a million!
推荐答案
A Map
映射
或设置
。看起来像你需要的是像 Map< Set< String>,String>
或者可能是 Map< Map< String,String> .Entry< String,String>>
- 不确定这些args1,args2是相关的。
A Map
's key can be another Map
or a Set
. Looks like all you need is something like a Map<Set<String>, String>
or perhaps a Map<Map<String, String>, Map.Entry<String, String>>
- not sure where these "args1","args2" are relevant.
这篇关于如何在Java中实现复杂字符串的集合(列表,映射?)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!