Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore case for 'contains' for a string in Java [duplicate]

Tags:

java

string

Consider:

public static void main(String[] args) {

    String s = "AbcD";

    System.out.println(s.contains("ABCD"));
    System.out.println(s.contains("AbcD"));
}

Output:

false
true

I need the result to be true in both cases regardless of the case. Is it possible?

like image 953
PSR Avatar asked May 17 '13 08:05

PSR


1 Answers

You need to convert both the strings to the same case before using contains

s.toLowerCase().contains("ABCD".toLowerCase());
like image 58
sanbhat Avatar answered Oct 21 '22 21:10

sanbhat