How-to articles, tricks, and solutions about COMPARISON

Comparing chars in Java

To compare two char values in Java, you can use the == operator, just like you would with any other primitive type. For example:

How do I do a case-insensitive string comparison?

You can convert both strings to lowercase or uppercase (using the lower() or upper() method) before doing the comparison.

How to compare dates in Java?

You can compare dates in Java by using the compareTo() method of the java.util.Date class. This method compares the date object on which it is called with the date object passed as an argument to the method

How to test multiple variables for equality against a single value?

In Python, you can test multiple variables for equality against a single value using the == operator.

Java Compare Two Lists

To compare two lists in Java, you can use the equals() method of the List interface.

Why does comparing strings using either '==' or 'is' sometimes produce a different result?

When comparing strings using the '==' operator, the comparison is based on the actual characters in the string.