0

I want to search for an object by getting the Id this is what I tried to do:

public Payment getPayment(int paymentId) {  

 for (Payment temp: payments) {
    if(temp.getPaymentId()==paymentId ) {

     return  temp;
    }
  }
   return null;
 }
}

It return the address

Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57
AAA
  • 17
  • 5

1 Answers1

1

Right now You are returning the Object. As you said that it is giving the address that means you are printing it.

Something like this

System.out.println(Object)

If it is showing address that means you haven't overridden the toString method

If you need to show all the properties of the object then, the efficient way to do this is to override ToString method

  @Override
public String toString()
{
   //Your properties here
}

Other way to do it will be printing the values by using the getter methods. You can easily generate these methods if you are using and IDE like eclipse or IntelliJ. or you can use Lombok

Silverfang
  • 349
  • 1
  • 8