Jan 31

Use the compareTo() method instead of the equals() method.
equals() only considers two BigDecimal’s to be equal if they have same value and scale (eg. 1.25 is not equal to 1.250 when using equals() method).

BigDecimal a = new BigDecimal("1.25");
BigDecimal b = new BigDecimal("1.250");
if (a.compareTo(b)==0)
{
   System.out.println("They are equal");
}

written by objects \\ tags: , ,

Jan 30

The Arrays class includes methods for testing the equality of two array. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal.

if (Arrays.equals(array1, array2))
{
  // array1 and array2 contain the same elements in the same order
}

written by objects \\ tags: , ,