字符串比较时,采用.intern()方法将字符串添加到驻留池中,再进行比较,运行速度比equals()方法更快 String str="张三";str=str.intern();if(str=="张三"){System.out.println("相同");}