Here is an example of comparing two strings for equality without considering their case sensitivity. To do this we can use equalsIgnoreCase()
method of the String
class. Let’s see an example below:
package org.kodejava.basic;
public class EqualsIgnoreCase {
public static void main(String[] args) {
String uppercase = "ABCDEFGHI";
String mixed = "aBCdEFghI";
// To compare two string equality regarding it case use the
// String.equalsIgnoreCase method.
if (uppercase.equalsIgnoreCase(mixed)) {
System.out.println("Uppercase and Mixed equals.");
}
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024