I am using this code, to get the index of a String in an Array.
int n = Arrays.asList(Names).indexOf(textBox.getText());
The problem here is, if the String in textBox is different in case to its similar String in the Array. It returns -1. How can make it something like equalsIgnoreCase in case of String comparision.
Thank You
You can use the Collator class. in Here you can set different levels for your comparison. you can ignore lower and upper cases, and set some specific language charackters. In German for example it can set ß equal to ss.
here´s some documentary: Collator class
Edit : here´s an example Code for you
private int indexOf(String[] original, String search) {
Collator collator = Collator.getInstance();
collator.setStrength(Collator.SECONDARY);
for(int i = 0;i<original.length;++i) {
if(collator.equals(search, original[i]))
return i;
}
return -1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With