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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:10:02+00:00 2026-06-01T20:10:02+00:00

I want to add, remove and replace values in a MultiMap provided by Guava.

  • 0

I want to add, remove and replace values in a MultiMap provided by Guava.

I do this currently to add values..

static Multimap<Integer, Float> myMultimap;
 myMultimap = ArrayListMultimap.create();
 myMultimap.put(1, (float)4.3);
 myMultimap.put(2, (float)4.9);
 myMultimap.put(1, (float)4.7);
 myMultimap.put(1, (float)4.5);

Removing values is easier with Guava library.

myMultimap.remove(1,(float)4.7);

But how can I use the replaceValues method?

I mean this

 myMultimap.replaceValues(1, (float)4.3);

Say I wanted to replace value 4.3 with a new value 5.99, how should I do that, the method expects some Iterable function and I am not sure as of how to implement it..

This is the error..

The method replaceValues(Integer, Iterable) in the
type Multimap is not applicable for the arguments (int,
float)

  • 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-06-01T20:10:03+00:00Added an answer on June 1, 2026 at 8:10 pm

    Multimap.replaceValues takes a collection of values that replaces all of the existing values for the given key. From the JavaDoc it looks like you need to use remove followed by put.

    If the map is modifiable, you can get a modifiable view on the collection of values mapped to a single key using get, but the view returned is a plain Collection without an atomic replace method. You can always create your own helper method. Note that this method is not thread-safe.

    public static <K,V> boolean replaceValue(Multimap<K,V> map, K key, V oldValue, V newValue) {
        if (map.remove(key, oldValue)) {
            map.put(key, newValue);
            return true;
        }
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Panel with a BottomToolbar . I want to add and remove dynamically
So I want to be able to add/remove class methods at runtime. Before you
What I want to do is add and remove list items. I have got
I want to remove a UIView from a superview and add it again at
I want add my custom sidebar next right column all page. Please check this
I have a list of string values that I want add to a hashtable
How can add/remove/replace LIST in cookies using C#. //Declaring the List for image list
Is there any ways I can do this? Find: if (value) _select.Add(X); else _select.Remove(X);
I want to remove and add a control at runtime on a Windows Forms
I have dbml with single table users i want add partial class for User

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.