hashCode():默认实现:根据对象的地址值生成一个唯一的哈希码值
toString():默认实现:打印对象的【类名+十六进制的哈希码值】
–重写后:Student自定义类打印的是类型+所有属性和属性值
equals():默认实现:比较两个对象的地址值,默认使用==比较
–重写后:比较的是两个对象的类型+所有属性和属性值
综上:如果执行的效果和Object的默认效果不同,说明子类重写了该方法
Stringpackage cn.tedu.api;
import java.util.Arrays;
import java.util.Locale;
public class TestString2 {
public static void main(String[] args) {
String s1 = "abc";
char[] c = {'a','b','c'};
String s2 = new String(c);
System.out.println(s1);
System.out.println(s2);
//测试常用方法
System.out.println(s1.hashCode());
System.out.println(s2.hashCode());
System.out.println(s1.equals(s2));//true,比较的是字符串的内容
System.out.println(s1.length()); //3,查看当前字符串的长度
System.out.println(s1.toUpperCase());
System.out.println(s1.toLowerCase());
System.out.println(s1.startsWith("a")); //判断字符串是不是以a开头的
System.out.println(s1.endsWith("a"));//判断字符串是不是以a结尾的
System.out.println(s1.charAt(0)); //根据下标获取字符串指定位置上的字符
String s3 = "abcdacab";
System.out.println(s3.indexOf("b")); //获取指定字符第一次出现的位置
System.out.println(s3.lastIndexOf("b"));
System.out.println(s2.concat("cxy")); //abccxy,拼接字符串,不会改变原串
System.out.println(s2);
String s4 = s2.concat("cxy");
System.out.println(s4);
String s5 = " hh hhhh ";
System.out.println(s5.trim()); //用于去除字符串首尾两端的空格
String s6 = "abcdefgh";
System.out.println(s6.substring(3)); //deghf,从指定下标劫取子串[3,结束]
System.out.println(s6.substring(3,6)); //def,从指定下标截取字串[3,6]
String s7 = "afbfcfdfe";
String[] fs = s7.split("f"); //以指定的字符串f分割字符串
System.out.println(Arrays.toString(fs));
System.out.println(String.valueOf(10)+10);//1010,将int类型的参数10转为String类型的"10"
byte[] bytes = s2.getBytes();//将字符串转为bute类型的数组
System.out.println(bytes);//[97,98,99]
}
}



