indexOf and contains don't use character encoding of any sort and you can use characters which are not used in your character encoding for example. i.e. it is ignored for these functions.
All String.indexOf() and contains do is compare character for character. I am not sure what behaviour you are expecting for 100% Arabic support. Here is a simplified version what the indexOf()/contains() does
public static int indexOf(String string, char[] chars) {
LOOP:
for (int i = 0; i < string.length() - chars.length; i++) {
for (int j = 0; j < chars.length; j++)
if (string.charAt(i + j) != chars[j])
continue LOOP;
return i;
}
return -1;
}
public static void main(String args[]) {
char[] chars = "test".toCharArray();
String one = "qqwtestq";
String two = "qwqtqwe";
String str = new String(chars);
System.out.println("indexOf(" + one+", " + Arrays.toString(chars) + ") = " + indexOf(one, chars));
System.out.println(one + ".indexOf(" + str + ") = " + one.indexOf(str));
System.out.println("indexOf(" + two+", " + Arrays.toString(chars) + ") = " + indexOf(two, chars));
System.out.println(two + ".indexOf(" + str + ") = " + two.indexOf(str));
char[] chars2 = { '\uffff', '\uFeFF' };
String test = "qqw\uffff\uFeFFq";
String str2 = new String(chars2);
System.out.println("indexOf(" + test+", " + Arrays.toString(chars2) + ") = " + indexOf(test, chars2));
System.out.println(test + ".indexOf(" + str2 + ") = " + test.indexOf(str2));
}
Prints
indexOf(qqwtestq, [t, e, s, t]) = 3
qqwtestq.indexOf(test) = 3
indexOf(qwqtqwe, [t, e, s, t]) = -1
qwqtqwe.indexOf(test) = -1
indexOf(qqw??q, [?, ?]) = 3
qqw??q.indexOf(??) = 3
Can you provide an example where this method doesn't work?
EDIT: This test checks every possible character to see if indexOf behaves as expected. i.e. the same for every possible character.
for(int i=Character.MIN_VALUE;i<= Character.MAX_VALUE;i++) {
String find = new String(new char[] {(char) i});
String str = new String(new char[] {(char) (i+1), (char) i});
String str1 = new String(new char[] {(char) (i+1)});
int test1 = str.indexOf(find);
if (test1 != 1)
throw new AssertionError("test1 failed i="+i);
int test2 = str1.indexOf(find);
if (test2 != -1)
throw new AssertionError("test2 failed i="+i);
}
Finds no discrepancies.