常用实用类
8.1 String类
判断引用是否为同一变量
String s=“we are students”;
String t=“we are students”;
上述 引用同一个变量
String s=new String(“we are students”);
String t=new String(“we are students”);
上述 引用的不是同一个变量
常量池vs非常量池(动态区)
动+常->动
equals
判定两个对象的内容是否一致,并不关心是否是同一个对象。
输出对象为内存地址的方式
me//直接输出某个对象
me.toString()//未改写/重载的toString
“==” 运算结果为ture/false的比较方式
常量比较值,变量比较引用
通常不会管是不是同一个对象,只看对象的内容是否相同。
即书上原句:
判断涉及java虚拟机机制
判断涉及字符比较.equals
you、hi自身都是变量->全变量
String类的常用方法
public int length()
public boolean equals(Sring s)
功能实例:学生系统中判断张三是几班的 20201124
public boolean startWith(String s)
public boolean endWith(String s)
public int compareTo(String s)
public boolean contains(String s)
public int indexOf(String s)