String StringBuilder 和 StringBuffer的区别
String的值是不可变的,这就导致每次对String的操作都会生成新的String对象,这样不仅效率低下,而且大量浪费有限的内存空间。因为String的底层使用Char字符实现的 而Char是用final类型修饰的,不可更改,所以是线程安全的String str = “hello”此时str 指向 常量池中的"hello"这时 会在常量池开辟一块内存存储 “hello” 字符串当执行str=str+“word!”此时str会切断与"hello"之间的引用 指向 “hellow word!”
原创
2020-09-06 20:57:09 ·
209 阅读 ·
0 评论