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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:38:06+00:00 2026-06-11T04:38:06+00:00

Firstly I created the ArrayList of Strings: List<List<String>> array1 = new ArrayList<List<String>>(); Then after

  • 0

Firstly I created the ArrayList of Strings:

List<List<String>> array1 = new ArrayList<List<String>>();

Then after populating it with data and doing a print:

[John, Smith, 120]
[Albert, Einstein, 170]

Now I want to loop through the list and do a comparison with say String[] array2 = {"Albert", "Einstein", "170"} and I’ve tried so far:

if (array1.get(i).equals(array2)) { blah }

However this is not working, I basically want traverse the arraylist and find if my array2 gets a match or not. How can I make this work?

  • 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-11T04:38:08+00:00Added an answer on June 11, 2026 at 4:38 am

    A list simply isn’t equal to an array. The simplest fix for this would be to wrap your array in a list first:

    if (array1.get(i).equals(Arrays.asList(array2))
    

    That will then use the equals implementation which just performs sequential equality checking on each item.

    If you just want to find the first matching entry, then using indexOf as per Louis’s answer will also work.

    I would also strongly suggest that you don’t call a variable array1 when it’s not an array.

    Finally, if you’re using List<String> just as a wrapper to avoid having to create a real data structure with (say) names and ages in, then don’t: create a Person class, so you end up with:

    List<Person> people = new ArrayList<Person>();
    Person testPerson = new Person("Albert", "Einstein", 170);
    

    … implement equality and hashing appropriately, and you’ll be good to go. Your code will be much simpler to read and maintain that way.

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

Sidebar

Related Questions

Firstly I created a collection which is Collection list; and in a function RSS
I have created firstly ASP.NET MVC 2 . and write more functionality. After I
Firstly, I have created a custom list definition based on the Tasks list in
i am new to xcode and objective c. firstly i have created a file
Firstly some background,.. IVe started a new job as PHP developer with a company
Firstly I would like to say that I am quite new to Spring (in
I am writing a graphical application using SWT. Firstly I created a shell with
Im learning Java and having a problem with ArrayList. Firstly I have a class
I created a new module and a new top level menu item in the
Firstly, I am new to both android and Java. I have two classes, my

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.