Object类
超类,基类,所有类的直接或间接父类,位于继承树的最顶层 任何类,如果没有书写extends显示继承某个类,都默认直接继承Object类,否则为间接继承 Object类中所定义的方法,是所有对象都具备的方法 Object类型可以存储任何对象
作为参数,可接受任何对象 作为返回值,可返回任何对象
GetClass()方法
public final Class<?>getClass(){}; 返回引用中存储的实际对象类型 应用:通常用于判断两个引用中实际存储对象类型是否一致.
hashcod
public int hashcode(){} 返回该对象的哈希吗值 哈希值根据对象的地址或字符串或数字使用hash算法计算出来的int类型的数值 一般情况下相同对象返回相同哈希吗
Integer
package AllClass;
public class Demo2 {
public static void main ( String[ ] args) {
Integer integer1 = new Integer ( 100 ) ;
Integer integer2 = new Integer ( 100 ) ;
System. out. println ( integer1== integer2) ;
Integer integer3 = 100 ;
Integer integer4 = Integer. valueOf ( 100 ) ;
System. out. println ( integer3== integer4) ;
Integer integer5 = 128 ;
Integer integer6 = Integer. valueOf ( 128 ) ;
System. out. println ( integer5== integer6) ;
}
}
String
字符串是常量,创建后不可改变 字符串字面值存储在字符串池中,可以共享
常用方法
public int length();返回字符串的长度 public char charAt(int index);根据下标获取字符 public boolean contains(String str);判断当前字符串中是否包含str public char[] toCharArray();将字符串转换成数组 public int indexOf(String str);查找str首次出现的下标,存在,则返回下标;不存在,则返回-1 public int lastIndexOf(String str);查找字符串在当前字符串中最后一次出现的下标索引 public String trim();去掉字符串前后的空格 public String toUpperCase();将小写转换成大写 public boolean endWith(String str);判断字符串是否以str结尾 public String replace(char oldCher,char newChar);将旧字符串替换成新字符串 public String[] split(String str);根据str做拆分 两种比较方法,equals,compare
package AllClass;
import java. util. Arrays;
public class Demo3 {
public static void main ( String[ ] args) {
String name = "Hello" ;
name = "zhangsan" ;
String name2 = "zhangsan" ;
String str = new String ( "Java" ) ;
String str2 = new String ( "Java" ) ;
System. out. println ( str. equals ( str2) ) ;
String str3 = "java是最好的编程语言,java真香" ;
System. out. println ( str3. length ( ) ) ;
System. out. println ( str3. charAt ( str3. length ( ) - 1 ) ) ;
System. out. println ( str3. contains ( "java" ) ) ;
System. out. println ( Arrays. toString ( str3. toCharArray ( ) ) ) ;
System. out. println ( str3. indexOf ( "java" , 5 ) ) ;
System. out. println ( str3. lastIndexOf ( "java" ) ) ;
String str4 = " hello world " ;
System. out. println ( str4. trim ( ) ) ;
System. out. println ( str4. toUpperCase ( ) ) ;
System. out. println ( str4. endsWith ( "java" ) ) ;
System. out. println ( str4. startsWith ( " hello" ) ) ;
System. out. println ( str3. replace ( "java" , "php" ) ) ;
String str5 = "Java is the best programing,language" ;
String[ ] arr= str5. split ( "[,+ ]" ) ;
System. out. println ( arr. length) ;
for ( String string : arr) {
System. out. println ( string) ;
String s1 = "Hello" ;
String s2 = "hello" ;
System. out. println ( s1. equals ( s2) ) ;
System. out. println ( s1. equalsIgnoreCase ( s2) ) ;
String s3 = "abc" ;
String s4 = "afg" ;
String s5 = "xyz" ;
String s6 = "abcsaf" ;
System. out. println ( s3. compareTo ( s5) ) ;
System. out. println ( s3. compareTo ( s4) ) ;
System. out. println ( s3. compareTo ( s6) ) ;
}
}
}