1. Object类
所有对象的父类
常用方法
- public boolean equals(Object obj):在Object类当中,该方法比较的是地址值。很多类都重写了该方法,例如String。重写方法后比较的是字面值。"=="对于基本类型比较的是值,对于引用数据类型则比较地址值
- protected Pnject clone(): 创建并返回此对象的一个副本。如果在没有实现Cloneable接口的实例上调用该方法会报错CloneNotSupportedException
Student s = new Student();
Object obj = s.clone();
Student s2 = (Student)obj;
2. Scanenr类
常用方法
- public boolean hasNextXxx():判断键盘输入的数据类型是否为Xxx
- public Xxx nextXxx():将输入信息的下一个当做Xxx类型数据返回
- public String nextLine():获取一行作为String返回
3. String类
String类保存的字面值全部放在一个常量池中,相同字面值的就不再创建新对象,而是直接拿常量池中的字面值。
常用方法
- public boolean equals(Object obj):比较的是内容,覆盖了Object的方法
- public boolean equalsIgnoreCase(String str):
- public boolean contains(String str):
- public boolean startWith(String str):
- public boolean endWith(String str):
- public boolean is Empty():
- public int length():
- public char charAt(int index):
- public int indexOf(int ch):
- public int indexOf(int ch,int fromIndex):
- public int indexOf(String str, int fromIndex):
- public String substring(int start):
- public String subString(int start,int end):
- public String valuefOf(char[] chs):字符数组转化成字符串
- public String toLowerCase():
- public String concat(String str):
- public String replace(char old,char new):
- public String replace(String old,String new):
- public String trim():去除两端空格