我们java是开源的,所以又很多类看不懂可以看底层代码。例如:
@Test
public void test1(){
String str = "asdfasdf";
char a = str.charAt(6);
System.out.println(a);
}
此时我们charAt究竟作用是什么,参数代表什么意思 返回值代表什么意思我们无从得之,所以可以ctrl+左键查看代码
/**
* Returns the {@code char} value at the
* specified index. An index ranges from {@code 0} to
* {@code length() - 1}. The first {@code char} value of the sequence
* is at index {@code 0}, the next at index {@code 1},
* and so on, as for array indexing.
*
* <p>If the {@code char} value specified by the index is a
* <a href="Character.html#unicode">surrogate</a>, the surrogate
* value is returned.
*
* @param index the index of the {@code char} value.
* @return the {@code char} value at the specified index of this string.
* The first {@code char} value is at index {@code 0}.
* @exception IndexOutOfBoundsException if the {@code index}
* argument is negative or not less than the length of this
* string.
*/
public char charAt(int index) {
if ((index < 0) || (index >= value.length)) {
throw new StringIndexOutOfBoundsException(index);
}
return value[index];
}
这个方法很慢,所以就有了API(Application Programming Interface,应用程序接口)文档,他有中文版 而且所有类都包含了,我们看起来就方便了
首先打开文档
我们发现其将java所有的类都罗列出来了
java中的常用包: lang java的语言核心包 io java的输入输出流 math 数学工具包
net java的网络包 sql java中数据库操作相关的包 util java的工具包
我们要使用得类是String 所以通过索引搜索String
A 继承关系
public final class String
extends Object
implements Serializable, Comparable<String>, CharSequence
B String的简介
C 构造方法
D 静态方法
E 接口方法
所以实现某个功能可以去百度