How to Ignore a Case Sensitive Input in Java
Some applications process character strings that, because of the nature of the information they contain, should not be case sensitive. A common example of this is email addresses. For those strings, comparisons should ignore the case of letters -- for example, "bob@aol.com" should be considered equal to "Bob@AOL.com." There's a simple way to write Java code that ignores the case of letters in the input.
Instructions
-
-
1
Include the following line at the beginning of your Java code:
import java.lang.String;
-
2
Store the string whose case must be ignored as an instance of Java class "String," as in the following sample code:
String myInput = "Bob@AOL.com";
-
-
3
Convert the string to lower case before storing it or comparing it with other values, as in the following sample code:
convertedInput = String.toLowerCase(myInput);
For the example, "convertedInput" will have value "bob@aol.com."
-
1