Q:

Tagging strings in Java

How can i tag an array of string in java ?
I want to make an array of strings and tag them like :
m funny
s funny 
t boring
k boring

Then if the user can search for them by tagging like 
search : funny
::
m,s

A:

// 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");

If one word can have multiple tags, then you might have another 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");

A:

I suggest using a Guava MultiMap of tags to strings.  This way you can get all the Strings with a given tag with a single lookup.
MultiMap<String, String> tagStringMap = new MultiMap<String, String>();

// load up the tag to strings.
tagStringMap.put(tag1, string1);

// single lookup gets everything.
Collection<String> strings = tagStringMap.get(tag);

