1. package test;
    2. public class Main {
    3. public static void main(String[] args) {
    4. String s1 = "WTY2002"; //s1 指向池中的 “WTY2002”
    5. String s2 = "java"; // s2 指向池中的 “java”
    6. String s5 = "WTY2002java"; //s5 指向池中的 “WTY2002java”
    7. String s6 = (s1 + s2).intern();//s6 指向池中的 “WTY2002java”
    8. System.out.println(s5 == s6); //T
    9. System.out.println(s5.equals(s6));//T
    10. }
    11. }

    image.png

    1. package test;
    2. public class Main {
    3. public static void main(String[] args) {
    4. }
    5. }
    6. class Test1 {
    7. String str = new String("hsp");
    8. final char[] ch = {'j', 'a', 'v', 'a'};
    9. public void change(String str, char ch[]) {
    10. str = "java";
    11. ch[0] = 'h';
    12. }
    13. public static void main(String[] args) {
    14. Test1 ex = new Test1();
    15. ex.change(ex.str, ex.ch);
    16. System.out.print(ex.str + " and ");
    17. System.out.println(ex.ch);
    18. }
    19. }

    image.png