Preface
Recently, I was learning Java and came into contact with long types. I found that the information on this aspect on the Internet was messy, so I decided to summarize that in Java we often have to make some judgments, and for judgment, the most common comparison is the comparison of ">", "==", and "<". Here we will explain the comparison sizes of Long type data and long type data. Without further ado, let’s take a look at the detailed introduction.
The difference between Long and Long in Java
There are two types of Java data types:
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
Among them, Long is also called long packaging. Byte and Float are similar. Generally, the first letter of the name of the packaging class is the capitalization of the numerical name.
The object types above are the basic type of wrapper classes, for example, Byte is the wrapper class of byte.
Java language is an object-oriented language, but the basic data types in Java are not object-oriented, which has many inconveniences when actually using them. In order to solve this shortcoming, a corresponding class is designed for each basic data type to represent when designing a class. In this way, the eight classes corresponding to the basic data type are collectively called Wrapper Class.
What is packaging?
In Java, sometimes the operation must be performed between two class objects, and the operation between objects and numbers is not allowed. So there needs to be an object that wraps the numbers so that this object can be calculated with another object.
For packaging classes, these classes mainly include two uses:
a. It exists as a class type corresponding to the basic data type, which facilitates the operation of objects.
b. Contains the relevant attributes of each basic data type such as maximum value, minimum value, etc., as well as related operation methods.
Comparison of the size of the Long data
For Long type data, this data is an object, so the object cannot be directly compared with ">", "==", and "<". If you want to compare whether the two objects are equal, we can use the Long object's.equals()
method:
Long l1 = new Long(100); Long l2 = new Long(200); ((l2));
If you want to compare ">" and "<", you can use the Long object's.longValue()
method:
Long l1 = new Long(100); Long l2 = new Long(200); (()<());
Comparison of long data sizes
For long type data, this data is a basic data type and does not belong to an object, so you can directly compare it with ">", "==", and "<"
long l3 = 300; long l4 = 400; (l3>l4); (l3<l4); (l3==l4);
Summarize
The above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.