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 873193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:53:43+00:00 2026-05-15T10:53:43+00:00

A Google Collections Multiset is a set of elements each of which has a

  • 0

A Google Collections Multiset is a set of elements each of which has a count (i.e. may be present multiple times).

I can’t tell you how many times I want to do the following

  1. Make a histogram (exactly Multiset)
  2. Get the top N elements by count from the histogram

Examples: top 10 URLs (by # times mentioned), top 10 tags (by # times applied), …

What is the canonical way to do #2 given a Google Collections Multiset?

Here is a blog post about it, but that code is not quite what I want. First, it returns everything, not just top N. Second, it copies (is it possible to avoid a copy?). Third, I usually want a deterministic sort, i.e. tiebreak if counts are equal. Other nits: it’s not static, etc.

  • 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-15T10:53:44+00:00Added an answer on May 15, 2026 at 10:53 am

    I wrote methods with the basic functionality you’re asking for, except that they perform copies and lack deterministic tie-breaking logic. They’re currently internal to Google, but we may open-source them at some point. This Guava issue has the method signatures.

    Their algorithm is similar to the blog post: sorting a list of entries. It would be faster, but more complicated, to use a better selection algorithm.

    EDIT: since Guava 11, this is implemented

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

Sidebar

Related Questions

Google Collections contains the Multiset interface and the TreeMultiset class, but I was surprised
Has anybody used TreeMultimap in Google Collections? I understand that with a TreeMultimap, its
How can you instantiate a Bimap of Google-collections? I've read the question Java: Instantiate
Has anyone had any luck rolling a custom GWT jar for Google Collections /
How can you compile the code using javac in a terminal by using google-collections
Since everyone praises Google Collections (e.g. in here ) How come I can't find
Google Collections has an Iterables utility class for taking in a collection and iterable
Before using google collections I had something similar to next code: private Set<A> aSet
I need to sort an ArrayList and i can't use Collections.sort(), because Google App
Is google collections Joiner thread safe?

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.