Beginner Beginner - 1 year ago 95
Java Question

Check if a specific string contains any lower/uppercase

Is there a way to check if a specific string contains any lower/upper case ?

E.G :

String myStr = "test";
if (myStr.contains("test") { // I would like this condition to
check the spell of "test", weather it is
written like "Test" or "teSt" etc...
//Do stuff

With this syntax, it works only for the exact same string. How could I make my condition for anyform of "test", like : "Test", "tEst", "tesT" etc... ?

Answer Source

You can use equalsIgnoreCase() method. This method compares two String with ignoring the case.

String a = "Test";

if("test".equalsIgnoreCase(a)) //returns true
  //do stuff
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download