Long值比较
long 128L == long 128L 值为false
Long的范围为-128~127当数值超过这个值时,就会new方法生成新的对象,而用等号比较的是地址,所以long 128L == long 128L 为false
Long值的比较一般通过 Long.equals() 或Long.longVale()进行比较
public class demo { public static void main(String[] args) { // TODO Auto-generated method stub Long long1 = 127L; Long long2 = 127L; Long long3 = 128L; Long long4 = 128L; System.out.println("long1 == long2 : " + (long1 == long2)); // true System.out.println("long3 == long4 : " + (long3 == long4)); // false System.out.println("long3.longValue() == long4.longValue() : " + (long3.longValue() == long4.longValue())); // true System.out.println("long3.equals(long4): " + long3.equals(long4)); //true } }