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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:21:35+00:00 2026-05-27T00:21:35+00:00

I have two arraylists, one contains Strings and the other contains Classes that have

  • 0

I have two arraylists, one contains Strings and the other contains Classes that have a String data member. The goal is to recurse through the objects in the second arraylist, and find which object’s string data member equals a string value in the first arraylist.

Now I understand that you cannot use the == operator to compare strings, so I initially used the equals method, and now I’ve tried the contentEquals method, however regardless of the method I choose the strings are always classified as equal – even when they are not. So whenever I run the code below, the “if” statement always returns true the first time it is called, regardless of whether the strings are actually equal.

Iterator stringListIter = stringList.iterator();
Iterator objectListIter = objectList.iterator();
while (stringListIter.hasNext())
{
    String currentString = (String) stringListIter.next();
    while (objectListIter.hasNext())
    {
        MyObject currentObject = (MyObject) objectListIter.next();
        String objectString = currentObject.getString();
        if (objectString.contentEquals(currentString));
        {
            //Do something here.....
            break;
        }
    }
}

Any help would be greatly appreciated. I get the feeling its probably something that is fairly simple, but I just can’t see it.

  • 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-27T00:21:36+00:00Added an answer on May 27, 2026 at 12:21 am

    The problem is you have an extraneous semicolon:

    if (objectString.contentEquals(currentString));
    

    This statement essentially does nothing so the following block is always executed.

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

Sidebar

Related Questions

I have two arraylists that contains links in one and the root url in
I have two arraylists. One contains filenames and the other contains failurecount. These values
I have two ArrayLists of different lengths. One contains ints, the other contains objects
I have a class that contains two arraylists which I'm trying to store objects
I have two very simple classes, one extends the other: public class LocationType implements
I have two applications written in Java that communicate with each other using XML
I have two classes, and want to include a static instance of one class
I have 2 ArrayLists that have a Array of Strings as a component. I
I have two ArrayList's that I am using, one for the enemy sprites and
I have two AsyncTasks as inner classes in my Activity . One returns an

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.