java - 在 Java 中标记字符串

标签 java

如何在 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/

相关文章:

java - 在 JAVA 对象中存储和获取值

java - 有什么想法可以让我的代码有效地循环 10 000 000 000 次

java - 如何使用分页和 spring data jpa 获取 findAll() 服务的所有记录?

java - 使用 spring-data-jpa 和 spring-mvc 过滤数据库行

java - Google Sheets API v4 Spreadsheets.Values.Update 返回错误 404 :Requested entity was not found

java - 生成随机数,不返回一些数字

java - 为什么我的对象不会死?

java - ParallelRefProcEnabled 默认线程数

java - String.getBytes() 和 IOUtils.toByteArray() 的区别?

java - RSS 项目顺序,重要吗?