The long type in java_The long type in Java and the Long type compare the size

In Java, we often have to make some judgments, and for judgments, the most used ones are ">", "==", "

Difference between Long and long in Java

There are two types of data types in Java:

1. Basic types: byte(8), short(16), int(32), long(64), float(32), double(64), char(16), boolean(1)

2. Object type: Byte, Short, Integer, Long, Float, Double, Character, Boolean

The above object types are the wrapper classes of basic types, for example, Byte is the wrapper class of byte

The Java language is an object-oriented language, but the basic data types in Java are not object-oriented, which brings a lot of inconvenience in actual use. A corresponding class is represented, so that the eight classes corresponding to the basic data types are collectively called the Wrapper Class

For wrapper classes, there are two main purposes of these classes:

a. It exists as a class type corresponding to the basic data type, which is convenient for operations involving objects.

b. Contains the relevant attributes of each basic data type, such as the maximum value, the minimum value, etc., as well as the related operation methods.

Comparison of the size of Long data

For data of type Long, this data is an object, so the object cannot directly pass ">", "==", "

Long l1 = new Long(100);

Long l2 = new Long(200);

System.out.println(l1.equals(l2));

If you want to do ">", "

Long l1 = new Long(100);

Long l2 = new Long(200);

System.out.println(l1.longValue()

Comparison of the size of long data

For data of type long, this data is a basic data type and does not belong to an object, so it can be directly passed ">", "==", "

long l3 = 300;

long l4 = 400;

System.out.println(l3>l4);

System.out.println(l3

System.out.println(l3==l4);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324084522&siteId=291194637