String和new String equal 对比

public class Animal {
	
	public static void main(String[] args) {
	
		String s = "hell";
		String sone = "hell";
		String stwo = new String("hell");
		String sthree = new String("hell");
		
		System.out.println(s==sone);
		System.out.println(s==stwo);
		System.out.println(s==sthree);
		System.out.println(stwo==sthree);
		
	}
}

 

 

猜你喜欢

转载自bugyun.iteye.com/blog/2334091