I am wondering why the parameter to indexOf method an int , when the description says a char.
public int indexOf(int ch)
Returns the index within this string of the first occurrence of the specified **character**
http://download.oracle.com/javase/1,5.0/docs/api/java/lang/String.html#indexOf%28int%29
Also, both of these compiles fine:
char c = 'p';
str.indexOf(2147483647);
str.indexOf(c);
a]Basically, what I am confused about is int in java is 32bit , while unicode characters are 16 bits .
b]Why not use the character themselves rather than using int . Is this any performance optimization ?. Are chars difficult to represent than int ? How ?
I assume this should be simple reasoning for this and that makes me know about it even more !
Thanks!
See Question&Answers more detail:os