How should I compare two characters of two CharSequences?
These are my two CharSequences:
CharSequence name1 = fname.getText();
CharSequence name2 = sname.getText();
If I try to compare like this:
if(name1[i] == name2[j])
..it gives me errors.
To compare particular
chars in your String, you can usechar charAt(int)method also fromStringtype. Here is example use:You have to remember that
char charAt(int)is zero-based so 0 is first, 1 is second and so on.And in this example you can see that I compared two chars just like I would compare
integers – with simple==.Comparing whole
Strings:To make it case insensitive you can use method from
StringtypetoLowerCase()on bothStrings.or: