String StringBuffer,StringBuilder 原理
String,StringBuffer,StringBuilder 是经常使用的,了解其原理十分重要
查看String源码
public final class String
implements java.io.Serializable, Comparable<String>, CharSequence {
/** The value is used for character storage. */
private final char value[];
/** Cache the hash code for the string */
private int hash; // Default to 0
/** use serialVersionUID from JDK 1.0.2 for interoperability */
private static final long serialVersionUID = -6849794470754667710L;
}
发现String底层的数据结构是 字符数组 char[]
其次 常用的String 操作:
1.创建对象
private static void testString() {
//查看下 str1 str2区别
String str1 = "hello world";
String str2 = new String("hello world");
String str