Differences in Java Long and long the

Differences in Java Long and long the

Java data types are divided into two types:

1, the basic types: byte (8), short (16), int (32), long (64), float (32), double (64), char (16), boolean (1)
2, object types: Byte, Short, Integer, Long, Float, Double, Character, Boolean

The above object types are primitive types of packaging, for example a byte Byte wrapper class.


Java is an object-oriented language, but the basic data types in Java is not an object-oriented, which there are many inconveniences in actual use, in order to solve this problem, in the design category for each data type basic design It is representative of a corresponding class, so that eight basic data types and corresponding class referred to as packaging (wrapper class)

For packaging that uses these classes mainly includes two kinds:

  • As the basic data types and the corresponding class type exists, easy operations involving the object.

  • Each type contains the basic data related to attributes such as maximum value, minimum value, and related methods of operation

Compare the size of the Long data

For Long type of data, the data is an object, so the object can not be directly through the ">" comparison "==", "<", if you want to compare two objects are equal, then we can use this Long .equals () method:

Long l1 = new Long(100);  
    Long l2 = new Long(200);  
        System.out.println(l1.equals(l2)); 

If you want to, ">", "<", then comparison, by a Long object .longValue () Method:

    Long l1 = new Long(100);  
            Long l2 = new Long(200);  
      
            System.out.println(l1.longValue()<l2.longValue());

Comparison of the data of the long

For long type of data, this data is a basic data types, are not covered, can be directly through the ">", "==", "<" for comparison

long l3 = 300;  
        long l4 = 400;  
  
        System.out.println(l3>l4);  
  
        System.out.println(l3<l4);  
  
        System.out.println(l3==l4); 

Guess you like

Origin blog.csdn.net/qq_36833171/article/details/93734249