I want to get a map with order and duplicates.
Map<String, Boolean> map = ?;
map.put("abc", true);
map.put("cba", true);
map.put("cba", true);
map.put("bca", false);
map.put("bac", false);
map.put("bca", true);
map.put("cab", true);
map.put("cba", true);
map.put("cba", false);
map.put("cba", true);
System.out.println(map);
I used LinkedHashMap, but It doesn't allow duplicates.
Expected: {abc=true, cba=true, cba=true, bca=false, bac=false, bca=true, cab=true, cba=true, cba=false, cba=true}
Retrieved: {abc=true, cba=true, bca=true, bac=true, cab=true}
Is there any implementation of map interface to achieve my goal?
UPD
Guava MultiMap doesn't fit into my issue.
Multimap<String, Boolean> map = ArrayListMultimap.<String, Boolean>create();
It prints
{cab=[true], abc=[true], cba=[true, true, true, false, true], bac=[false], bca=[false, true]}
UPD2
I found solution. Apache Commons provides Tuple type Pair.
So my code may look like this
List<Pair<String, Boolean>> list = new ArrayList<>();
list.add(new ImmutablePair("abc", true));
list.add(new ImmutablePair("cba", true));
list.add(new ImmutablePair("cba", true));
list.add(new ImmutablePair("bca", true));
list.add(new ImmutablePair("bac", true));
list.add(new ImmutablePair("bca", true));
list.add(new ImmutablePair("cab", true));
list.add(new ImmutablePair("cba", true));
list.add(new ImmutablePair("cba", true));
And now it prints
[(abc,true), (cba,true), (cba,true), (bca,true), (bac,true), (bca,true), (cab,true), (cba,true), (cba,true)]
But I'm still sure that it just should be some good implementation of proper map.