I want to know how to make whatever the user inputs to ignore case in my method:
public static void findPatient() {
if (myPatientList.getNumPatients() == 0) {
System.out.println("No patient information is stored.");
}
else {
System.out.print("Enter part of the patient name: ");
String name = sc.next();
sc.nextLine();
System.out.print(myPatientList.showPatients(name));
}
}
You ignore case when you treat the data, not when you retrieve/store it. If you want to store everything in lowercase use String#toLowerCase, in uppercase use String#toUpperCase.
Then when you have to actually treat it, you may use out of the bow methods, like String#equalsIgnoreCase(java.lang.String). If nothing exists in the Java API that fulfill your needs, then you'll have to write your own logic.
use toUpperCase() or toLowerCase() method of String class.
The .equalsIgnoreCase() method should help with that.
I have also tried all the posted code until I found out this one
if(math.toLowerCase(Locale.ENGLISH));
Here whatever character the user input will be converted to lower cases.
Use String#toLowerCase()
or String#equalsIgnoreCase()
methods
Some examples:
String abc = "Abc".toLowerCase();
boolean isAbc = "Abc".equalsIgnoreCase("ABC");
Source: Stackoverflow.com