package com; /** * 1) 字符串是有字符数组组成的 * 2) 字符串"对象"是不可改变的, 字符串引用可以重新赋值 * 3) Java 中为了提高性能, 静态字符串在静态池中创建, 尽量使用同一个对象. 重用静态字符串 */ public class Demo05 { public static void main(String[] args) { //2) 字符串"对象"是不可改变的, 字符串引用可以重新赋值 String s1 = "Hello"; String s2 = s1; s1 = s1 + " World!"; //生成了新字符串对象, 原字符串对象不变! //字符串的连接底层是字符数组复制实现的! System.out.println(s1);//Hello World! System.out.println(s2);//Hello //3) Java 中为了提高性能, 静态字符串在静态池中创建, 尽量使用同一个对象. 重用静态字符串 String s3 = "123ABC"; String s4 = "123ABC"; System.out.println(s3==s4);//true } } |
|