Q: Java - Searching table for an object with a matching String I'm searching through a table for a customer with a matching name, if found then I want to return that customer, otherwise return null. The problem is I'm getting null all the time, I think my problem is with the if in the inner for loop.
public class testter
{
    public Customer isCustomerInTable(Customer[][] table, String customerName) {
        for ( int r = 0; r < table.length; r++ ) {
            for ( int c = 0; c < table[r].length; c++ ) {
                if ( table[r][c].equals(customerName) ) {
                    return table[r][c];
                }
            }
        }
        return null;
    }
}

My customer class:
class Costumer {

    private String name;

    public Customer()  {
        name = "";
    }

    public void setCostumerName(String name) {
        this.name = name;
    }

    public String getCostumerName(){
        return name;
    }
}

Any ideas? Thanks

A: You if condition should be 
if (table[r][c].getCostumerName().equals(customerName))

You need to compare the names, but in your case, you are comparing the Customer object with the String customerName.

A: You are checking Customer object with a string. That's the reason. You should do the following
if ( table[r][c].getCostumerName().equals(customerName) ) {
    return table[r][c];
}

