Could someone explain to me why is the result is 6? Thanks
String[] s = { "A", "B", "C", "D" };
String b = "ABRACADABRA";
int i = s.length - 1;
System.out.print( b.indexOf( s[ i ] ) );
I understand s length is 4, so i = 3, but then what does s[i] mean?
In Java strings and arrays are 0-indexed. This means that the first element has index 0, the second element has index 1, etc…
So
s[3]means the fourth element ofswhich isD. The expressionb.indexOf("D")is 6 becauseDis the seventh letter inABRACADABRAand so it is at index 6.