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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:19:10+00:00 2026-05-16T03:19:10+00:00

I have set up a HashMap like so: Map<String, ArrayList<String>> theAccused = new HashMap<String,

  • 0

I have set up a HashMap like so:

Map<String, ArrayList<String>> theAccused = new HashMap<String, ArrayList<String>>();

… and I populate this by storing for every name (key), a list of names (value). So:

ArrayList<String> saAccused = new ArrayList<String>();
// populate 'saAccused' ArrayList
...
// done populating
theAccused.put(sAccuser, saAccused);

So now, I want to look through all of the entries in the HashMap and see if (for each ‘sAccuser’), the list ‘saAccused’ contains a certain name. This is my failed attempt so far:

Set<String> setAccusers = theAccused.keySet();
Iterator<String> iterAccusers = setAccusers.iterator();
iterAccusers.next();
ArrayList<String> saTheAccused;

// check if 'sAccuser' has been accused by anyone before
for (int i = 0; i < theAccused.size(); i++) {
    saTheAccused = theAccused.get(iterAccusers);

    if (saTheAccused.contains(sAccuser)) {

    }
    iterAccusers.next();
}

… however I’m not sure how the Set and Iterator classes work :/ The problem is that I don’t have the “values”… the names… the 'sAccuser's… for the HashMap available.

In a nutshell, I want to iterate through the HashMap and check if a specific name is stored in any of the lists. So how can I do this? Let me know if you need me to go into further detail or clear up any confusion.

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-05-16T03:19:11+00:00Added an answer on May 16, 2026 at 3:19 am

    In a nutshell, I want to iterate through the HashMap and check if a specific name is stored in any of the lists. So how can I do this?

    There’s two ways of iterating through the map that might be of interest here. Firstly, you can iterate through all of the mappings (i.e. pairs of key-value relations) using the entrySet() method, which will let you know what the key is for each arraylist. Alternatively, if you don’t need the key, you can simply get all of the lists in turn via the values() method. Using the first option might look something like this:

    for (Map.Entry<String, ArrayList<String>> entry : theAccused.entrySet())
    {
       String sListName = entry.getKey();
       ArrayList<String> saAccused = entry.getValue();
       if (saAccused.contains(sAccuser))
       {
          // Fire your logic for when you find a match, which can
          // depend on the list's key (name) as well
       }
    }
    

    To answer the broader questions – the Set interface simply represents an (unordered) collection of non-duplicated values. As you can see by the linked Javadoc, there are methods available that you might expect for such an unordered collection. An Iterator is an object that traverses some data structure presenting each element in turn. Typical usage of an iterator would look something like the following:

    Iterator<?> it = ...; // get the iterator somehow; often by calling iterator() on a Collection
    while (it.hasNext())
    {
       Object obj = it.next();
       // Do something with the obj
    }
    

    that is, check whether the iterator is nonexhausted (has more elements) then call the next() method to get that element. However, since the above pattern is so common, it can be elided with Java 5’s foreach loop, sparing you from dealing with the iterator itself, as I took advantage of in my first example.

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

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, your webserver can examine the USER_AGENT string that comes… May 16, 2026 at 11:13 pm
  • Editorial Team
    Editorial Team added an answer When num1*num2 is computed, it is stored in an intermediate… May 16, 2026 at 11:13 pm
  • Editorial Team
    Editorial Team added an answer Curiously an array also has overloads for GetItem that take… May 16, 2026 at 11:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following code: Map<String, ObjectType> objectMap = new HashMap<String, ObjectType>(); for (ObjectType
I find myself using a lot of nested maps, e.g a Map[Int, Map[String, Set[String]]],
i have set sesssion lik this Session[page + GridView1.PageIndex] = values; Now hwen next
I want to write a map-like object type in PL/SQL. What I mean is
I'm trying to map a collection (of type map) using a foreign key and
I have set up jqGrid with JSON in my .Net MVC project. The grid
I have set Private Memory limit of 200mb in IIS 7 for an application
I have set up a website (www.autobodypartsnow.com) and the search function has gone haywire.
I have set up a my application with spanish and english. On my console
I have set the base SDK to iPhone Device 4.0 and the deployment target

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.