0
            System.out.println("Inside loop");
            System.out.println(customer.getCustId());
            System.out.println(customer.getPhone());
            System.out.println(transaction.getCustId());
            if(transaction.getCustId() == customer.getCustId()) {
                System.out.println("Found one transaction");
                System.out.println(transaction);
                filteredTransaction.add(transaction);
            }
        }

This is my code. The values for the fields on if statement are same but still the if statement doesn't get executed.

Here is the output I am getting.

Inside loop
446bdfd3-3d09-43e7-83df-1883f967d296
9818122018
446bdfd3-3d09-43e7-83df-1883f967d296
Inside loop
446bdfd3-3d09-43e7-83df-1883f967d296
9818122018
446bdfd3-3d09-43e7-83df-1883f967d296
Inside loop
446bdfd3-3d09-43e7-83df-1883f967d296
9818122018
446bdfd3-3d09-43e7-83df-1883f967d296
Inside loop
446bdfd3-3d09-43e7-83df-1883f967d296
9818122018
446bdfd3-3d09-43e7-83df-1883f967d296
Inside loop
446bdfd3-3d09-43e7-83df-1883f967d296
9818122018
446bdfd3-3d09-43e7-83df-1883f967d296
Inside loop
446bdfd3-3d09-43e7-83df-1883f967d296
9818122018
446bdfd3-3d09-43e7-83df-1883f967d296
  • If CustId fields are strings - use .equals() instead of == . == tests for reference equality (whether they are the same object). .equals() tests for value equality (whether they contain the same data). – user3240544 Jan 02 '23 at 09:16
  • I missed to add the for on top which is: for(Transaction transacation: allTransaction){ – Bibek Bhattarai Jan 02 '23 at 09:17
  • But there is no option for that, only available choices are .equals() which need two objects for comparision and .equalIgnoreCase which is not what I want. – Bibek Bhattarai Jan 02 '23 at 09:20
  • Not sure I understand the problem regarding, "which need two objects for comparison". You have two objects: `transaction.getCustId().equals(customer.getCustId())`. – Slaw Jan 02 '23 at 09:22
  • "_I missed to add the for on top which is..._" -- You can [edit] your question to make any necessary changes. – Slaw Jan 02 '23 at 09:23
  • Thanks! This solved it but there is another problem again. The transaction inside if statement doesn't get added to filtered transaction although there is matching transaction. – Bibek Bhattarai Jan 02 '23 at 09:28
  • Create a [mre] demonstrating the problem. That may lead you to finding a solution yourself, but if not then ask a new question (and don't forget to provide the [mre]). – Slaw Jan 02 '23 at 09:32

0 Answers0