1

I want duplicate values + natural order + empty, which collection support these features?

I have tried Multihashmap and TreeMultimap. Treemultimap didn't allow empty values, even I have key, but its allowing...

public static void main(String[] args) { 
    TreeMultimap<String, String> mp = TreeMultimap.create();
    StringBuilder b = new StringBuilder();
    mp.put("a", "10"); 
    mp.put("a", "11"); 
    mp.put("a", "12"); 
    mp.put("b", "13"); 
    mp.put("c", "14"); 
    mp.put("e", "");
    mp.put("b", "1");
    mp.put("b", "2");
    mp.put("b", "3");
    List list = null; 
    for(String key : mp.keySet())  
    {
        System.out.println("mp.values()"+mp.values());
        int itemcount = mp.size();
        System.out.println(itemcount);

    }

expected output format as

a 10 11 12 
a 10 11 12
a 10 11 12
b 13 1 2 3
b 13 1 2 3
b 13 1 2 3
b 13 1 2 3
c 14
e
MBO
  • 30,379
  • 5
  • 50
  • 52
user2444474
  • 623
  • 8
  • 21
  • 40
  • Why did you tag this with [tag:oracle] and [tag:sql]? If there's some relation to these tags, please mention it in the text. Otherwise they don't apply. – Joachim Sauer Jun 03 '13 at 05:22
  • I'm just wondering , last 3 hours i didn't get any feedback.But normally responses are very fast in stackoverflow. – user2444474 Jun 03 '13 at 05:22
  • 3
    So that's why you add unrelated tags to get some more input? That's an abuse of the system. Instead, try to update your question with additional findings or details (for example, what's the *actual* output of your code?) – Joachim Sauer Jun 03 '13 at 05:24
  • Yes, front layer looks very hard to achive this scenrio.Thats reason i would have added sql, to get resultset sa above format. – user2444474 Jun 03 '13 at 05:24
  • Possible duplicate of [Adding a key with an empty value to Guava Multimap](http://stackoverflow.com/questions/11587895/adding-a-key-with-an-empty-value-to-guava-multimap) – amaidment Dec 05 '16 at 17:27

1 Answers1

2

That's very deliberately how Multimap works. Putting an empty String and a normal String into a Multimap makes exactly no difference, and a Multimap will treat a key without any values as completely nonexistent. Please read Multimap Is Not A Map from the Guava wiki.

Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413