That's why the gods invented the equals method in java.lang.ObjectIf getName() returns a String then simply do:if ( getName().equals(nameSearch) ) {System.out.println("wow. it is working");}