0

I am working on a Java project and I am making a simple Comparison, I Imagine the issue is staring me in the face but its been a few days and could use a new set of eyes.

public class Reservation {
    String tripID;
    String tripDate;
    String customerNum;

    Reservation() {

    }

    public void setID(String s) {
        this.tripID = s;
    }

    public String getID() {
        return this.tripID;
    }

    public void setDate(String s) {
        this.tripDate = s;
    }

    public String getDate() {
        return this.tripDate;
    }

    public void setNum(String s) {
        this.customerNum = s;
    }

    public String getNum() {
        return this.customerNum;
    }

}

I have a list of Reservations stored as

List<Reservation> listReservation = new ArrayList<>();

While running the comparison for a customerNum that the user enters stored as userInput

for(Reservation rs : listReservation) {
    if(rs.getNum().toString() == userInput) {
        System.out.println(rs.getDate());
    }
}

The list will never make a match, for the sake of ease the list of use numbers is as fallows 101 101, 101, 103, 104, 105, 106, 107, 108, 109, 102, 102, 115, 116, 119, 120, 121, 122, 126, 124, 124, 112, 119, 121, 125, 126, 120, 104.

Thank you in advance.

dapi
  • 1
  • 1

1 Answers1

0

Try changing this

rs.getNum().toString() == userInput

to

rs.getNum().toString().equals(userInput)

Shoaeb
  • 709
  • 7
  • 18
  • Thank you, you are 100% right. I knew it had to be an easy fix I simply couldn't see. @Shoaeb – dapi Apr 21 '20 at 05:27