Java8 基础数据类型包装类-Long
基础
//final修饰不可更改,每次赋值都是新建类(其中-128~127是通过LongCache数组获取的不是新建的,所以可以使用==比较,但其他数据是通过new创建的,不能使用==直接比较大小,因为是不同的类,地址不同,需用equals)
public final class Long extends Number implements Comparable<Long> {}
- 1
- 2
常量
//-2^63
@Native public static final long MIN_VALUE = 0x8000000000000000L;
//2^63-1
@Native public static final long MAX_VALUE = 0x7fffffffffffffffL;
//位数
@Native public static final int SIZE = 64;
//字节数
public static final int BYTES = SIZE / Byte.SIZE;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
继承
抽象类Number
获取包装类与基本类型之间的转换值,short、int、long、byte、float、double。
实现
Comparable 接口
实现compareTo(T o)方法
私有静态内部类
//初始化是-128~127的Long对象
private static class LongCache {
private LongCache(){}
static final Long cache[] = new Long[-(-128) + 127 + 1];
static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Long(i - 128);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
方法
转成特定进制的字符串
//i:数值
//radix:需要转换的进制(2~36 不在此范围的按10进制处理)
public static String toString(long i, int radix) {}
//默认转成10进制,当i==MIN_VALUE 直接返回数值"-9223372036854775808"
public static String toString(long i) {}
//调用toString(long i)
public String toString() {}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
按无符号数值转特定进制的字符串,BigInteger
//无符号数转字符串
//i:数值
//radix:需要转换的进制(2~36 不在此范围的按10进制处理)
public static String toUnsignedString(long i, int radix) {}
private static BigInteger toUnsignedBigInteger(long i) {}
//转化成16进制无符号字符串
public static String toHexString(long i) {}
//转化成10进制无符号字符串
public static String toUnsignedString(long i) {}
//转化成8进制无符号字符串
public static String toOctalString(long i) {}
//转化成2进制无符号字符串
public static String toBinaryString(long i) {}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
字符串转long
//s:数值字符串
//radix:s字符串是几进制(radix不在2~36则抛异常)
public static long parseLong(String s, int radix) throws NumberFormatException{}
//字符串为10进制
public static long parseLong(String s) throws NumberFormatException {}
//无符号字符串转long(字符串第一位为“-”抛异常)
//radix:表示s字符串是几进制(radix不在2~36则抛异常)
public static long parseUnsignedLong(String s, int radix) throws NumberFormatException {}
//字符串为10进制
public static long parseUnsignedLong(String s) throws NumberFormatException {}
字符串,long转Long
//s:数字型字符串
//radix:表示s字符串是几进制(radix不在2~36则抛异常)
public static Long valueOf(String s, int radix) throws NumberFormatException {}
//默认为10进制
public static Long valueOf(String s) throws NumberFormatException{}
//其中-128~127的Long是程序启动时就已经保存到LongCache中,所以在这个范围的数据是直接取的LongCache中的值
public static Long valueOf(long l) {}
//nm:可以是010(8进制)、0x10(16进制)(#开头的在这个方法中也表示16进制)
public static Long decode(String nm) throws NumberFormatException {}
Long转基本数据类型
public byte byteValue() {}
public short shortValue() {}
public int intValue() {}
public long longValue() {}
public float floatValue() {}
public double doubleValue() {}
获取系统属性的值
//nm:系统属性的名称
//val:如果为空时的默认值
public static Long getLong(String nm, long val) {}
public static Long getLong(String nm, Long val) {}
//返回默认值为null
public static Long getLong(String nm) {}
比较及求和
//返回-1,1,0(-1表示y大,1表示x大)
public int compareTo(Long anotherLong) {}
//返回-1,1,0(-1表示y大,1表示x大)
public static int compare(long x, long y) {}
//比较xy无符号数的大小,返回-1,1,0(-1表示y大,1表示x大)
public static int compareUnsigned(long x, long y) {}
public static long sum(long a, long b) {}
public static long max(long a, long b) {}
public static long min(long a, long b) {}
无符号数运算
//将dividend和divisor转成无符号整数相除取整
public static long divideUnsigned(long dividend, long divisor) {}
//将dividend和divisor转成无符号整数相除取余
public static long remainderUnsigned(long dividend, long divisor) {}
位运算
同Integer
Java8 基础数据类型包装类-Long的更多相关文章
- java基础数据类型包装类
*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...
- JAVA基础--常用类 String,StringBuffer, 基础数据类型包装类, Math类, Enum类
字符串相关类: String, StringBuffer String类为不可变的字符序列 String s1="hello"; String s2="hello&quo ...
- 面试题:基础数据类型 包装类 int Integer
因为在学习集合时知道集合里存放的对象都是Object类型,取出的时候需要强制类型转换为目标类型(使用泛型集合不需要),如int a = (Integer)arrayList.get(0):然后我们就会 ...
- 黑马程序员——JAVA基础之基本数据类型包装类和1.5JDK新特性装箱
------- android培训.java培训.期待与您交流! ---------- 基本数据类型包装类: byte Byte short Short int Integer char Charac ...
- Java基础---String类和基本数据类型包装类
第一讲 String类 一.概述 String是字符串的类类型,用于描述字符串事物.字符串是一个特殊的对象.特殊之处就在于: Stings= new String();和Str ...
- 黑马程序员----java基础:String与StringBuffer及基本数据类型包装类
------- android培训.java培训.期待与您交流! ---------- java中一些基础类比如String.StringBuffer和基本数据类型包装类都是非常常见且使用非常频繁的类 ...
- [五]基础数据类型之Short详解
Short 基本数据类型short 的包装类 Short 类型的对象包含一个 short 类型的字段 原文地址:[五]基础数据类型之Short详解 属性简介 值为 215-1 ...
- Java - 关于基础数据类型的形参和返回值
1. 当基础数据类型被当作形参时,最好使用其包装类,因为这样可方便调用者传参(基础数据类型亦或是其包装类都可) 2. 当基础数据类型被当作返回值时,最好使用原型,因为这样可以方便调用者接收返回值( ...
- java基础-数据类型之殇
一 前言 Java的数据类型分为2种,分别是基本数据类型和引用数据类型:java的数据类型是强数据类型,意味着每声明一个变量,其必定有与之对应的数据类型:面试常问的java8大基本数据类型其实是基本数 ...
随机推荐
- 38861cba61c66739c1452c3a71e39852.ttf net::ERR_ABORTED 404 (Not Found)
error: http://localhost:63342/clappr-dev/js/38861cba61c66739c1452c3a71e39852.ttf net::ERR_ABORTED 40 ...
- mysql 根据日期时间查询数据
mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | t ...
- 「ZJOI2019」Minmax搜索
传送门 Solution 叶子节点的变化区间是连续的,可得知非叶子节点的权值变化区间也是连续的 由此可知,\(W\)的变化值的可行域也是连续的,所以只需要看它能否变为\(W+1\)或\(W-1\) 对 ...
- 咕泡学院java架构vip课程
1.wps文档地址 https://docs.qq.com/doc/DRVNLUndvTmFSdEhO 2.百度网盘地址 https://pan.baidu.com/s/1uxaTzJZHKrsw_H ...
- 深度学习图像配准 Image Registration: From SIFT to Deep Learning
Image Registration is a fundamental step in Computer Vision. In this article, we present OpenCV feat ...
- OpenFOAM——具有压差且平行平板间具有相对运动流动
本算例翻译整理自:http://the-foam-house5.webnode.es/products/chapter-1-plane-parallel-plates-case/ 这个算例中两平板间具 ...
- es6学习2:变量的解构赋值
一:数组的解构赋值 ES6 允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构 let [foo, [[bar], baz]] = [1, [[2], 3]]; foo bar ba ...
- (未完成)catalyst-system WriteUp(2019暑假CTF第一周reverse)
目录 预备学习--Linux实践:ELF文件格式分析 一.概述 二.分析ELF文件头(ELF header) 三.通过文件头找到section header table,理解其内容 四.通过secti ...
- shell中$(( ))、$( )、``与${ }的区别
转 :shell $(( )).$( ).``与${ }的区别 $( )与` `(反引号)命令替换 在bash中,$( )与` `(反引号)都是用来作命令替换的.命令替换与变量替换差不多,都是用来重组 ...
- 第06组 Alpha冲刺(4/4)
队名:福大帮 组长博客链接:https://www.cnblogs.com/mhq-mhq/p/11913386.html 作业博客 :https://edu.cnblogs.com/campus/f ...