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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:46:53+00:00 2026-06-02T17:46:53+00:00

I have an arraylist of integer arrayslists and an arraylist of names. I’d like

  • 0

I have an arraylist of integer arrayslists and an arraylist of names. I’d like to add a certain number to one of those integer arraylists when it corresponds with a particular name and add a 0 to every other arraylist. I think that what I have should work, but it simply adds a 0 to everything and ignores the special case when the name is right. “Rating” is an integer, and “user” is a string. “Names” is an arraylist of strings. The language is Java.

for(int i = 0; i<names.size(); i++)
            {   

                if (names.get(i)==user)

                    allratings.get(i).add(rating);

                if (names.get(i)!=user) 

                    allratings.get(i).add(0);
            }   

Is there something wrong with my syntax? When I insert a print line, I find that my names arraylist and my allratings arraylist are perfectly matched up. Where am I going wrong?

  • 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-02T17:46:54+00:00Added an answer on June 2, 2026 at 5:46 pm

    Use .equals() when comparing Strings in Java:

    if (user.equals(names.get(i)))
    

    Comparing Strings in Java with == will compare references, which might not be what you want. It seems that the references are different, even though they hold the same string. This is why your condition is always returning false. You want to compare the actual value of the string. This is done with .equals().

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

Sidebar

Related Questions

I have a map like this, Map<Integer,ArrayList<Object>> myMap = new LinkedHashMap<Integer,ArrayList<Object>>(); Now I have
I have arraylist myorderdata . I want to retrieve this arraylist to one String
I want to add both String and Integer type of value in ArrayList. For
I have a program that add persons to an arraylist. What I'm trying to
I have a logic problem. User is allowed to add any number of fields
So I have this method which will take an ArrayList of Integers, I compare
At the moment inside the class I have ArrayList which the objects are stored
I have an arraylist that gets different type of values in it, 1st value->
I have an arraylist which has a class datastructure. public class empRec { public
I have an arraylist set up. I have input instuctions set up too, so

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.