Love dumplings: Long type and long type in Java comparison size

Source: Internet
Author: User

In Java we often have to make some judgments, and for judgment, the most used is the ">", "= =", "<" comparison, here we do a long type of data and long data comparison of the size of the explanation.

The difference between a long and long in JavaThere are two types of data in Java:1. Basic type:byte (8), short(+),int (+), long (+), float (+), double (+), char (+), Boolean (1)2. Object type: Byte,short,integer,long,float,double,character,boolean
the above object types are basic types of wrapper classes, 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 in the actual use of a lot of inconvenience, in order to solve this shortcoming, in the design of the class for each basic data type to design a corresponding class to represent, The classes that correspond to the eight basic data types are collectively referred to as wrapper classes (Wrapper Class)

For the wrapper class, the use of these classes consists of two main types:

A, as the basic data type corresponding to the class type exists, convenient to involve the operation of the object.

b, contains the relevant attributes for each basic data type, such as maximum, minimum, and related methods of operation.

comparison of the size of Long datafor long type of data, this data is an object, so the object can not be directly through the ">", "= =", "<" comparison, if you want to compare the equality of two objects, we can use the. Equals () method of the Long object:
Long L1 = new long (+);    Long L2 = new long (n);        System.out.println (L1.equals (L2));

If you want to make a comparison of ">", "<", you can use the long object's. Longvalue () Method:
Long L1 = new long (+);        Long L2 = new long (n);        System.out.println (L1.longvalue () <l2.longvalue ());

comparison of the size of Long datafor Long data, this data is a basic data type, not an object, so it can be compared directly with ">", "= =", "< "
Long L3 = +;        Long L4 = n;        System.out.println (L3>L4);        System.out.println (L3<L4);        System.out.println (L3==L4);



Love dumplings: Long type and long type in Java comparison size

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.