我想知道为什么indexOf方法的参数是int类型,而不是char类型,因为描述中明确写着是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]在Java中,int是32位的,而Unicode字符是16位的,我感到困惑的是为什么不直接使用字符本身而要使用int。这样做有没有性能优化?用字符表示比int难吗?怎么难?
b]我认为应该有简单的原因,这使我更加想了解它!
谢谢!