Home > Java > javaTutorial > body text

Detailed analysis of Java data type Long

不言
Release: 2018-09-26 14:17:01
Original
9596 people have browsed it

This article brings you a detailed analysis of the Java data type Long. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Long

Long The wrapper class of the basic data type long

Long type The object contains a long type field

Detailed analysis of Java data type Long

Property Introduction

A constant whose value is 263-1, which represents the maximum value that the long type can represent @Native public static final long MAX_VALUE = 0x7ffffffffffffffffL;
is a constant with a value of -263, which represents the smallest value that the long type can represent Value @Native public static final long MIN_VALUE = 0x8000000000000000L;
is used to The two's complement form represents the number of bits of the long value @Native public static final int SIZE = 64;
The two's complement form represents the number of bytes of the long value public static final int BYTES = SIZE / Byte.SIZE;
Represents a Class instance of the basic type long public static final Class TYPE = (Class) Class.getPrimitiveClass("long");

##Construction method

Construction methods are to create new objects and allocate new space

Constructed in string form, parsed in decimal string form by default

Common methods

Comparison

Packaging classUse the corresponding basic data type long to construct
Detailed analysis of Java data type Long
##Packaging class

Constructed using the String form of the corresponding basic data type long

Detailed analysis of Java data type Long
int compareTo(Long anotherLong)
Copy after login
##
static int compareUnsigned(long x, long y)
Copy after login

parseXXX series

Strings are parsed into basic types

No objects are required, so all It is a static method

Detailed analysis of Java data type Long

static int compare(long x, long y)
Copy after login

##Static method

0 x == y;

-1 x < y;

1 x > y

Detailed analysis of Java data type Long

Instance methodCompare two objects, actually compare the value of the two objects
Basically still call static int compare(long x, long y)

Detailed analysis of Java data type Long
Static methodTwo basic types of int are compared as unsigned numbers and converted through MIN_VALUEIt is still called static int compare(long x, long y)


Detailed analysis of Java data type Long
##static long parseLong(String s)static Decimal simplified form of method ##static long parseUnsignedLong(String s, int radix)Static method static long parseUnsignedLong(String s)
static long parseLong(String s, int radix)


Static methodUse the base (base) specified by the second parameter to parse the string parameter into a signed integer
Except that the first character can be the ASCII minus sign '-' ('\u002D') and the plus sign ' ' ('\u002B') used to represent negative values ​​
The characters in the string must be specified The number of the base


static long parseLong(String s, int radix)

Detailed analysis of Java data type Long


Use the second one The base (base) specified by the parameter, parses the string parameter into an unsigned integer

except that the first character can be an ASCII plus sign ' ' ( '\u002B') External

The characters in the string must be numbers in the specified base


##static methodstatic long parseUnsignedLong(String s, int radix) decimal simplified form


Detailed analysis of Java data type Long

valueOf series

Pack basic basic types into objects

Used to create and obtain objects , so there is no need for objects, they are all static methods

Detailed analysis of Java data type Long

##The VaueOf series has a corresponding cache area, and objects within the cache area For the same

buffer is an array in a static inner class

Detailed analysis of Java data type Long

# #The buffer range is -128~127

static Long valueOf(long l)Static methodsstatic Integer valueOf(String s, int radix)Static method#static Long valueOf(String s) Decimal parsing string##decode


Read objects in the cache or create new objects

Detailed analysis of Java data type Long


Parses the string according to the specified radix (base) Basically call static Long valueOf(long l)


Detailed analysis of Java data type Long



Static method
static Long valueOf(String s, int radix)Basically call static Long valueOf(long l)



Detailed analysis of Java data type Long

Accepts decimal, hexadecimal and octal numbers given by the following syntax ##Sign DecimalNumeral The codes are also exactly the same, except that Integer is replaced by Long

Sign is an optional symbol bit

Then DecimalNumeral is the positive value of the character sequence specifying the base

It cannot be a negative number. If you want to set a negative number, please just use the sign bit, which is -1 --1. This will definitely not work.

Sign 0x HexDigits

Sign 0X HexDigits

Sign # HexDigits

Sign 0 OctalDigits

Sign:

-

is the same as the decode method in Integer

XXXValue系列

获取对象的某种基本类型的值

需要获取对象的所以必然全部都是实例方法

Detailed analysis of Java data type Long

强制类型转换的形式,将内部的long 值转换为指定的类型

byte byteValue()
Copy after login


Detailed analysis of Java data type Long
short shortValue()
Copy after login
Detailed analysis of Java data type Long
int intValue()
Copy after login
Detailed analysis of Java data type Long
long longValue()
Copy after login
Detailed analysis of Java data type Long
float floatValue()
Copy after login
Detailed analysis of Java data type Long
double doubleValue()
Copy after login
Detailed analysis of Java data type Long


toUnsignedString 系列 toString toXXXString 系列

无符号 字符串相关的转换

static String toString(long i, int radix)
Copy after login

静态方法

根据指定基数,int 返回一个String

如果基数小于 Character.MIN_RADIX 或者大于 Character.MAX_RADIX,默认设置为基数 10

如果是负数 第一个符号位负号 '-' ('\u002D'),如果不是负数,将不会有符号

剩下的字符表示第一个参数的大小

如果大小是0 由字符 '0' ('\u0030') 表示,否则用来表示数值的第一个字符不会是0

用以下 ASCII 字符作为数字:

0123456789abcdefghijklmnopqrstuvwxyz

其范围是从 '\u0030' 到 '\u0039' 和从 '\u0061' 到 '\u007A'

如果 radix 为 N, 则按照所示顺序,使用这些字符中的前 N 个作为其数字

因此,十六进制(基数为 16)的数字是 0123456789abcdef

static String toString(long i)
Copy after login

静态方法

toString(long i, int radix)的十进制简化形式

同toString(long i, 10)

String toString()
Copy after login

实例方法

等同于把对象的value直接调用 toString(long i)

Detailed analysis of Java data type Long

static String toBinaryString(long i)
Copy after login

静态方法

以二进制(基数 2)无符号整数形式返回一个整数参数的字符串表示形式

Detailed analysis of Java data type Long

static String toOctalString(long i)
Copy after login

静态方法

以八进制(基数 8)无符号整数形式返回一个整数参数的字符串表示形式

Detailed analysis of Java data type Long

static String toHexString(long i)
Copy after login

静态方法

以十六进制(基数 16)无符号整数形式返回一个整数参数的字符串表示形式

Detailed analysis of Java data type Long

static String toUnsignedString(long i, int radix)
Copy after login
静态方法

在第二个参数指定的基数中,返回第一个参数的字符串表示的无符号整数值

如果基数不在Character.MIN_RADIX 和 Character.MAX_RADIX的范围内, 默认基数为10

如果大小是0,由字符零表示 '0' ('\u0030')

否则第一个字符不会是 0

基数和表示数字的字符的用法和表现和toString中一样

static String toUnsignedString(long i)
Copy after login
静态方法
toUnsignedString(long i, int radix) 十进制的简化形式 同toUnsignedString(int, 10)
Detailed analysis of Java data type Long

equals


Long重写了equals方法
比较的是两个Long对象中内部的 long value值
Detailed analysis of Java data type Long

hashCode


static int hashCode(long value)
Copy after login
静态方法
返回某个long 数值的hashcode
Detailed analysis of Java data type Long
int hashCode()
Copy after login
实例方法
获取某个Long对象的hashcode
等同于static int hashCode(long value) 调用 内部value值

Detailed analysis of Java data type Long

getXXX系列

获取系统属性的数值

static Long getLong(String nm, Long val)
Copy after login

确定具有指定名称的系统属性的整数值

第一个参数被视为系统属性的名称

通过 System.getProperty(java.lang.String) 方法可以访问系统属性

第二个参数是默认值

如果未具有指定名称的属性,或者属性的数字格式不正确,或者指定名称为空或 null

则返回一个表示第二个参数的值的 Integer 对象

Detailed analysis of Java data type Long
static Long getLong(String nm, long val)
Copy after login
static Long getLong(String nm, Long val) 的基本类型形式
Detailed analysis of Java data type Long
static Long getLong(String nm)
Copy after login

Detailed analysis of Java data type Long

其他方法

最高1 位 最低1 位
前置零个数 和 后置0个数

highestOneBit(long) / lowestOneBit(long)

numberOfLeadingZeros(long) / numberOfTrailingZeros(long)

位数
循环左移/循环右移
按位翻转 按照字节翻转


bitCount(long) 二进制补码表示形式中的 1 位的数量

rotateLeft(long, int) / rotateRight(long, int)

reverse(long) / reverseBytes(long)

取整
求余

pideUnsigned(long, long)

remainderUnsigned(long, long)

与Integer 一样, Long也有提供上述几个方法

语义一致

static int signum(long i)
Copy after login
静态方法
返回指定 int 值的符号函数
(如果指定值为负,则返回 -1;如果指定值为零,则返回 0;如果指定的值为正,则返回 1 )
Detailed analysis of Java data type Long
static long sum(long a, long b)
Copy after login
静态方法
求和
Detailed analysis of Java data type Long
static long max(long a, long b)
Copy after login
静态方法
最大值
Detailed analysis of Java data type Long
static long min(long a, long b)
Copy after login
静态方法
最小值
Detailed analysis of Java data type Long

Long 与Integer 是数值类型中使用频率最高的两个,也是提供支持方法最多的两个

他们提供出来的方法功能也是高度的相似

The above is the detailed content of Detailed analysis of Java data type Long. 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