I have a Set<> of strings:
Set<String> mySet = new HashSet<String>();
hs.add("how");
hs.add("are");
hs.add("you");
I want to turn this set into a string, however there is two rules:
- ":*" should be added as suffix to each word
- The words should be separated with a pipe |
Like this:
"how:*|are:*|you:*"
What is the most simple way to do this?
This is what I've tried so far:
StringBuilder sb = new StringBuilder();
for (String word : search) {
sb.append(word);
sb.append(":*|");
}
The problem with this is that it gives an extra pipe in the end:
"how:*|are:*|you:*|"
I can of course delete the last character, but I'm looking for a simpler way if possible.