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

The Archive Base Latest Questions

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

I’m trying to select and get values from customer objects. What I want to

  • 0

I’m trying to select and get values from customer objects. What I want to do is to enter a personal number like “702312” and search after the customer objects that has a data member personal number that are equal to “702312”. And when I found it I want to get the rest of the values or change it’s content. This is some code that creates the customer objects from the class Customer and then it’s stored in a arraylist.

// create a new customer object and send personal number, name and account number to constructor
Customer customer = new Customer(personalNumber, name, newAccountNumber);

// create an arraylist to store customer objects
ArrayList<Customer> customerList = new ArrayList<Customer>();

// add the new customer object to arraylist that holds all customer objects
customerList.add(customer);

I have tried to reach the values like this, but it’s not working, so I’m looking for some help?

 // search for customer
 for (Customer customer : customerList) {
if(customer.getAccountOwnerPersonalNumber() == "702312"){
    System.out.println("OK!!!");
    }
 }

And instead of:

 if(customer.getAccountOwnerPersonalNumber() == "702312")...

I have tried this:

 if(customer.personalNumber == "702312")...

Finally I have also tested it like this:

for(int i=0;i<customerList.size();i++){
    if(customerList.get(i).getAccountOwnerName() == "702312");
    System.out.println("OK");
    break;
}

I’m not sure if I’m doing right!? Help is preciated! 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-27T00:27:09+00:00Added an answer on May 27, 2026 at 12:27 am

    You need to use the equals() method to compare objects like Strings by their internal value (otherwise they will only be compared by reference):

    if (customer.getAccountOwnerPersonalNumber().equals("702312")) {
        System.out.println("OK!!!");
    }
    

    or, better, if it can potentially return null:

    if ("702312".equals(customer.getAccountOwnerPersonalNumber())) {
        System.out.println("OK!!!");
    }
    

    or, if applicable, just make it a primitive like int, so that == will work the way you intended:

    private int accountOwnerPersonalNumber;
    

    with

    if (customer.getAccountOwnerPersonalNumber() == 702312) {
        System.out.println("OK!!!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.