0

I use Guava library.

Is there any way to get in Multimap in each value?

For example, The value is 1=[stack], 2=[over, flow], 3=[com] in Multimap. If Multimap name is map and key is 2, map.get("2") will appear [over, flow].

I want to get only "flow". Is it posible?

m4tx
  • 4,139
  • 5
  • 37
  • 61
pamiers
  • 355
  • 1
  • 3
  • 11
  • You can try `.get(1)` I'm not at all sure about the return type of `map.get("2")`, though. – nhahtdh Jul 12 '12 at 08:46
  • Oh my god! I guess stupid thing. – pamiers Jul 12 '12 at 08:52
  • Based on your questions http://stackoverflow.com/questions/11427031/i-want-to-use-index-about-randomly-index-in-java and http://stackoverflow.com/questions/11444628/if-i-use-hashmapstring-arrayliststring-in-java I would suggest that you what you are trying to achieve needs a bit more thought. Think about your higher level concept once more and ask a question about that if necessary (e.g. *I want to cache entries where the key is an arbitrary integer; the cache should return one of the elements if queried*) – nd. Jul 12 '12 at 08:52

1 Answers1

5

A Multimap returns a Collection<X>, it sounds like you need the last item in that list, in that case you just need to get the list by calling map.get("2") and retrieve the last/n-th item in the list.

Guava has a class named Iterables which could prove useful to you. for example

String lastValue = Iterables.getLast(your_list);
epoch
  • 16,396
  • 4
  • 43
  • 71