If the class implements comparable, you could also do
int compRes = a.compareTo(b);
if(compRes < 0 || compRes > 0)
System.out.println("not equal");
else
System.out.println("equal);
doesn't use a !
, though not particularly useful, or readable....