选择项目添加jar包,导入包 import org.junit.Test;
import org.junit.Test;
public class TestString {
@Test
public void testConstantPool(){
String str1 = "Hello";
//不会创建新的String对象,而是使用常量池中已有的Hello
String str2 = "Hello";
System.out.println(str1 == str2);
}
}
测试成功!