Assuming this is Guava, this is just the one line
Lists.newArrayList(multimap.keys())
or, if you have an ImmutableListMultimap
,
multimap.keys().asList()
(Note here that Multimap.keys()
is a Multiset<Integer>
, which iterates over elements exactly in the way you want -- that is, it will have one occurrence of each key for each value associated with that key.)