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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:17:03+00:00 2026-06-17T19:17:03+00:00

I have a Map and a List My list a master list of some

  • 0

I have a Map and a List My list a master list of some value object and Map contains keys which are id of the value object
I have a value object

 public class Value
{


    private int id;

    private String value;

//set and gets to follow
}

Map valueMap = new HashMap();   

valueMap.put(1001,"Test1")//key is id of the value object 
valueMap.put(1002,"Test2")
valueMap.put(1003,"Test3")


 List list = new Array list();
 list.add(value1)
 list.add(value2)
 list.add(value3)
 list.add(value4)
 list.add(value5)

From the list i want to extract a subset of list whose value.id is ==key of map

how can i do and iterate over both?

  • 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-17T19:17:04+00:00Added an answer on June 17, 2026 at 7:17 pm

    You should use

    Map<Integer, String> valueMap = new HashMap<>();
    

    and

    List<Value> list = new ArrayList<>();
    

    Then, you can do something like this:

    List<Value> subset = new ArrayList<>();
    Iterator<Value> iterator = list.iterator();
    while (iterator.hasNext()) {
        Value val = iterator.next();
        if (valueMap.containsKey(val.getId())) {
            subset.add(val);
        }
    }
    

    or even

    List<Value> subset = new ArrayList<>();
    for (Value val : list) {
        if (valueMap.containsKey(val.getId())) {
            subset.add(val);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unordered map: class O(val a: Int) Map[String, List[O]] which I'd like
I have a map declared as follows: map < string , list < string
I have a List of keys say 'ListA'. And a map of keys &
I have a collection of the form: map<key, list<object> > I only ever insert
I have the following ArrayList ArrayList<HashMap<String, String>> list; HashMap<String, String> map; with the following
I have a Map of Lists with key = GROUP and value = List
I have a map which contains integer values. i want to re-arange this map
I have a list which contains various docIds. When the information is to be
I have a Map and a List . The List should be sorted based
I have a map of the USA and a list of long, lat that

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.