0

On my Android app I'm using Multiset:

Multiset<String> multiset = HashMultiset.create();

I want to convert it to a String using toString() method. The problem is that when it's a single item from every String then it looks OK, but when there are multiple strings with the same text, it is shown as [] instead of [A x 2, B, C x 3] for example.

How can I fix this so it will be shown as above instead of []?

pawel-schmidt
  • 1,125
  • 11
  • 15
Ido Naveh
  • 2,442
  • 3
  • 26
  • 57
  • 3
    IIUYC you're claiming that `HashMultiset#toString` with strings is broken. I find this extremely improbable as it's been testet and used a lot. I'd bet that there's an error elsewhere, try to reproduce it in a [SSCCE](http://sscce.org/) and post it. – maaartinus Apr 02 '17 at 16:51

1 Answers1

0

The easiest way is to convert Multiset to Set by calling Multiset#elementSet method:

Set<String> set = multiset.elementSet();

Then just call toString on this method to get the desired result.

pawel-schmidt
  • 1,125
  • 11
  • 15