Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7701921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:06:33+00:00 2026-05-31T23:06:33+00:00

I really like the Multimap class of the google guava library. It is a

  • 0

I really like the Multimap class of the google guava library. It is a map type where you can add multiple values for a key, so it effectively maps from a key to a collection of some type. What I especially love is the Multimaps.index() function which takes an Iterable and a key function and returns a Multimap which groups (or indexes or maps) the elements of the Iterable by the value the function returns for each of those elements.

What I find a bit strange is that Multimap.values() returns a flat collection instead of a collection of collections? So the grouping the index function gave me is lost once Ì retrieve the values. I can circumvent that problem by calling Multimap.asMap() and then call values() on that.

Does anyone know why it may make sense that Multimap behaves that way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:06:34+00:00Added an answer on May 31, 2026 at 11:06 pm

    Multimap.asMap().values() isn’t a way around the problem — it was deliberate that Multimap provides both ways of accessing it, getting a Collection<Collection<V>> via asMap().values() and getting the flattened Collection<V> with values().

    More generally speaking, Multimap tries not to just be “a map to collections,” but rather “a general way to associate keys with multiple values.” So you get the entries() method in addition to values() and keys(). The asMap() view provides a way to treat it as a “map to collections,” but that has very different semantics that aren’t always what you’re looking for.

    In any event, the values method is just meant to fill a different niche than the one filled by asMap().values().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really like how Gables.com has created their custom Google Map InfoWindows and Markers
I really like the way gmail has the archive system implemented. I can archive
I really like the format and type of links from RubyFlow for Ruby related
I really like Entity Framework, but there are some key pieces that are a
I really like the anchor and mousetrackign and the basic tooltps http://www.extjs.com/examples/explorer.html#tooltips How can
I really like git but unfortunately only can submit to a subversion repository. Is
I really like how in Rails 3 you can ask a scope for its
I really like the zx key combination in Vim (it folds everything but the
Would really like to be able to decorate my class with an attribute of
I really like using Factory Girl to setup my tests. I can build chains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.