package com.javalainxi;
public class StringDemo4 {
public static void main(String[] args){
String s1 = "Programming";
String s2 = new String("Programming");
String s3 = "Program";
String s4 = "ming";
String s5 = "Program" + "ming";
String s6 = s3 + s4;
System.out.println(s1 == s2); //false
System.out.println(s1 == s5); //true
System.out.println(s1 == s6); //false
System.out.println(s1 == s6.intern()); //true
System.out.println(s2 == s2.intern()); //false
}
}
在java 中,直接使用==操作符,比较的是两个字符串的引用地址,并不是比较内容,比较内容请用String.equals()。
关于static
public class HaHa {
class Inner {}
public static void foo() {
// new Inner(); //错误
new HaHa().new Inner();//正确
}
public void bar() { new Inner(); }
public static void main(String[] args) {
//new Inner();//错误
new HaHa().new Inner();//正确
}
}