如何在 java 中标记字符串数组?
我想制作一个字符串数组并将它们标记为:
m funny
s funny
t boring
k boring
然后如果用户可以通过标记来搜索它们
search : funny
::
m,s
最佳答案
// key is tag, value all the strings which have this tag.
HashMap<String, HashSet<String>> tags = new HashMap<String, HashSet<String>>();
// words that with the tag: funny
Set<String> words = tags.get("funny");
如果一个词可以有多个标签,那么你可能会有另一张 map :
// key is string, value all the tags for the string
HashMap<String, HashSet<String>> invertedTags = new HashMap<String, HashSet<String>>();
// tags of the word: "m"
Set<String> tags = invertedTags.get("m");
关于java - 在 Java 中标记字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5514355/