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

  • Home
  • SEARCH
  • 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 9231555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:05:56+00:00 2026-06-18T06:05:56+00:00

I would be really grateful if you could help me with that. Map<String, Double>

  • 0

I would be really grateful if you could help me with that.

Map<String, Double> movieMap = new HashMap<String, Double>;
movieMap.add("MovieA", 3);
movieMap.add("MovieB", 5);
movieMap.add("MovieC", 4);
movieMap.add("MovieD", 3.5);
movieMap.add("MovieE", 2.5);

Map<String, Double> movieMap2 = new HashMap<String, Double>;
movieMap2.add("MovieA", 3.5);
movieMap2.add("MovieB", 2.5);
movieMap2.add("MovieC", 4.5);
movieMap2.add("MovieD", 2);
            .
            .
            .
Map<String, Double> movieMapi = new HashMap<String, Double>;
movieMap2.add("MovieA", 5);
movieMap2.add("MovieC", 1.5);
movieMap2.add("MovieD", 2);

Map<String, Map<String, Double>> userMap = new HashMap<String, Map<String, Double>>;
userMap.add("Nick", movieMap);
userMap.add("Bill", movieMap2);
           .
           .
           .
userMap.add("Tom", movieMapi);

What i want to do is to make a function compare(userA, userB) and put the common movies and their rates into a new Map. By way of example the output of compare(Nick,Tom) should be a Map with keys – values : {{“MovieA”, {5,3}}, {“MovieC”, {4,1.5}}, {“MovieD”, {3.5,2}}}

It seems pretty hard for me to solve it..Can you please help me?
Thanks…

  • 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-18T06:05:57+00:00Added an answer on June 18, 2026 at 6:05 am

    You can iterate over the keys in a map using the Map.keySet() method:

    Set<String> nickKeys = userMap.get("Nick").keySet();
    Set<String> tomKeys = userMap.get("Tom").keySet();
    

    Your code might look something like this:

    Map<String, Double> nickMap = userMap.get("Nick");
    Map<String, Double> tomMap = userMap.get("Tom");
    
    Map<String, List<Double>> commonMap = new HashMap<String, List<Double>>();
    
    for (String movieName : nickMap.keySet()) {
        if (tomMap.containsKey(movieName)) {
            List<Double> tempList = new ArrayList<Double>();
            tempList.add(nickMap.get(movieName));
            tempList.add(tomMap.get(movieName));
            commonMap.put(movieName, tempList);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would be really grateful if somebody could help me out with this.. I
I would really appreciate it if some of you could help optimize my tables,
I would really like to add an image into the Sandcastle generated help file
I would be really grateful if someone could shed some light on this for
I would be really grateful if someone could explain how to show/ Hide UItoolbar
I would be very grateful if anyone could help me out with this problem.
I would be very grateful if someone could help me break through this issue
I would really appreciate any jquery expert help as a method I've used previously,
I would really appreciate if you could shed light on this problem. I have
I would really like your help in knowing the procedure to delete a .3gp

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.