构造方法
String()
String(byte[] bytes)
String(byte[] bytes, Charset charset)
String(byte[] ascii, int hibyte)
String(byte[] bytes, int offset, int length)
String(byte[] ascii, int hibyte, int offset, int count)
String(byte[] bytes, int offset, int length, String charsetName)
String(byte[] bytes, String charsetName)
String(char[] value, int offset, int count)
String(int[] codePoints, int offset, int count)
String(StringBuffer buffer)
String(StringBuilder builder)
String类的hash
Hash是根据String的内容来制作的一个String对象的内存地址的压缩。代表着压缩后的String对象的内存地址,而这个地址是由String内容来分配的。公式是
H=31*H+str.charAt[i];
String 类的 intern方法
intern方法使的String对象在创建前,先到String的常量池中查看要创建的内容是否存在于常量池,如果存在则直接使用,如果不存在则添加该内容到String常量池。
String s1 = new String(“aaa”);
String s2 = “aaa”;
s1==s2 ==>flase
String s1 = new String(“aaa”).intern();
String s2 = “aaa”;
s1 == s2 ==> true;
regionMatches方法 区域匹配。指定该字符串的起始位置和其他字符串的起始位置,开始比较len个长度的字符,返回boolean,相等返回true。equalsIgnore是基于此函数实现,equals不是。
regionMatches(boolean ignoreCase,int toffeset,String other,int ooffset,int len)
在忽略大小写进行比较的时候,后台是将字符toUpperCase进行一次比较,再将字符toLowerCase进行一次比较。