使用构造方法创建的字符串都是在堆中创建,不同于直接String str ="str1"这种方式在公共池创建,相同的字符串只会创建一个对象。每使用一次构造方法都会创建一个String对象,哪怕是相同内容的字符串。
//创建空白字符串
new String()
//根据字符串创建字符串
new String(String original)
//根据字符数组创建字符串
new String(char value[])
//截取字符数组创建字符串,offset为开始索引,count为长度
new String(char value[], int offset, int count)
//将int转化成char再根据参数截取内容转化成字符串
new String(int[] codePoints, int offset, int count)
//将bytes[]转化成字符串
new String(byte bytes[])
//将bytes[]转化成字符串,offset为开始索引,length为长度
new String(byte bytes[], int offset, int length)
//将StringBuffer转化成字符串
new String(StringBuffer buffer)
//将StringBuild转化成字符串
public String(StringBuilder builder)