“&&”和”&”都是java中的逻辑运算符,并且它们都表示“逻辑与”即“同真则真,有一假则假”,它们的区别在于”&&”具有短路功能,即如果左边是false,则右边的逻辑表达式不会执行.而”&”没有短路功能,无论左边是false还是true右边都会执行. public class Test { public static void main(String[] args) { System.out.println(false&&(1/0==0))…
==比较的是对象的地址,也就是是否是同一个对象: equal比较的是对象的值. Integer r1 = new Integer(900);//定义r1整型对象Integer r2 = new Integer(900);//定义r2整型对象System.out.println(r1==r2);//返回falseSystem.out.println(r1.equal(r2));//返回true =============equal是用来判断一个字符串的,比如:String s = test;if…
java String 是不可改变的类型. String a = "hello2"; String d = "hello"; final String b = "hello"; String c = b + "2";// final相当于常量,编译阶段直接加入常量池 String cc = “hello”+“2”: 类似于 final修饰的,在编译期间,会自动优化处理为:hello2 并加入常量池,所以和a比较相等,和e比较不…