Home > Java > JavaBase > body text

The difference between long and Long in java

王林
Release: 2019-11-18 13:39:58
Original
6005 people have browsed it

The difference between long and Long in java

The difference between long and Long in java is:

1. Long is the basic data type in java, and Long is an object in java Type;

2. For Long type data, the data is an object, while for long type data, the data is a basic data type and does not belong to an object.

Java data types are divided into two 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.

The above object types are wrapper classes of basic types. For example, Byte is a wrapper class of byte.

The Java language is an object-oriented language, but the basic data types in Java are not object-oriented, which causes a lot of inconveniences in actual use. In order to solve this shortcoming, when designing classes, A corresponding class is designed to represent each basic data type, so the eight classes corresponding to the basic data types are collectively called packaging classes.

As for wrapper classes, these classes mainly have two uses:

Exist as class types corresponding to basic data types to facilitate operations involving objects.

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

Comparison of the size of Long data

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

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

If you want to compare ">", "< "For comparison, you can use the .longValue() method of the Long object:

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

Comparison of the size of long data

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

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

Recommended tutorial :JavaTutorial

The above is the detailed content of The difference between long and Long in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template