equals vs Arrays.equals in Java

array1.equals(array2) is the same as array1 == array2, i.e. is it the same array. As @alf points out it’s not what most people expect. Arrays.equals(array1, array2) compares the contents of the arrays. Similarly array.toString() may not be very useful and you need to use Arrays.toString(array).

Is False == 0 and True == 1 an implementation detail or is it guaranteed by the language?

In Python 2.x this is not guaranteed as it is possible for True and False to be reassigned. However, even if this happens, boolean True and boolean False are still properly returned for comparisons. In Python 3.x True and False are keywords and will always be equal to 1 and 0. Under normal circumstances in … Read more

How do I compare strings in Java?

== tests for reference equality (whether they are the same object). .equals() tests for value equality (whether they are logically “equal”). Objects.equals() checks for null before calling .equals() so you don’t have to (available as of JDK7, also available in Guava). Consequently, if you want to test whether two strings have the same value you … Read more