首页 技术 正文
技术 2022年11月16日
0 收藏 679 点赞 4,928 浏览 2662 个字

基本类型的包装类

byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean

Number 数字类型包装类的抽象父类

她的子类:

Byte,Short,Integer ,Long,Float,Double

BigDecimal,BigInteger

取出被封装的基本类型值

byteValue();

shortValue();

intValue();

longValue();

floatValue();

doubleValue();

Integer

创建对象;

new Integer(5);

Integer.value(5);

Integer 实例内部, 有一个Integer 实例的缓存数组,

缓存着256个 Integer 对象,

封装的数字范围-128-127

valueOf()方法,指定范围的值,

访问存在的缓存对象,指定范围外的值,

直接新建对象

方法:

字符串解析成 int

Integer.parseInt(“225”);

Integer.parseInt(“111111”,2);二进制

Integer.parseInt(“377”,8);8进制

进制转换:

Integer.toBinaryString(255);转换二进制;

Integer.toOctalString(255);转换8进制

Integer.toHexString(255);转换十六进制

Double

    创建对象:

new Double(3.14);

Double.value(3.14);

两者没有区别

方法:

字符串解析

Double.parseDouble(“3.14”);

Byte.parseByte();

Short.parseShort();

Integer.parseInteger();

Long.parseLong();

Float.parseFloat();

Double.parseDouble();

Boolean.parseBoolean();

char 没有字符串解析方法,

判断浮点数特殊值

Infinity      Double.IsInfinite(double d);

nan          Double.isNan(double d);

自动装箱,

       Integer a = 5;

       自动编译为:  Integer a = Integer.valueOf(5);

自动拆箱

       int i = a;

       自动编译为 int i = a.intValue();

       a = a +  1;

       a = Integer.valueOf(a.intValue()+1);

       自动拆箱要当心 null 

BigDecimal , BigInteger

      BigDecimal 用来做精确的浮点数运算

BigInteger 来做超大的整数运算

BigDecimal

      创建对象:

      BigDecimal.valueOf(2);

      new BigDecimal(“2”);

      

      方法

      add(BigDecimal);          加

      subtract(BigDecimal);   减

      multiply(BigDecimal);    乘

      divide(BigDecimal);       除,不支持无理数(无限小数 )

     bigDecimal.pow(n);        求 bigDecimal 的 n 次方 

     

      divide(BigDecimal,保留位数,舍入方式);

      setScale(保留位数,舍入方式);  ROUND_HALF_UP(四舍五入)

保留位数 0: 0位 , 1: 1位 , -1:10位 , -2: 100位

      舍入运算,舍入结果被封装成一个新对象

      位数过长可以用 toString();输出

       

BigInteget 超大长整型运算

Date    java.util.Date

      封装一个毫秒值, 标识一个具体的时间点,  

      标识 距离 1970年1月1号0点 的时间点

     创建对象:

     new Date();// 无参构造,  封装系统当前时间的毫秒值

     new Date(9000000000L);// 封装指定的毫秒值

     

    方法

    getTime();

    setTime();

    compareTo(Date d);   //当前日期 与 参数日期 比较大小

    当前对象大,返回正数,否则负数,判断正负即可.0表示相同

SimpleDateFormat   java.text.SimpleDateFormat

    日期格式工具

    把 Date 对象格式化成指定的时间格式

    把时间格式字符串解析成 Date 对象

  

   创建对象

     new SimpleDateFormat(格式);

     格式 yyyy-MM-dd HH:mm:ss

      (大写M:月, 小写m:分,H:24小时制,h:12小时制)

     例如 yy-M-d

   方法

     format(Date);// Date 对象 格式化成字符串

     parse(String);// 日期格式字符串,解析成Date 对象

集合

     数组的缺点;

       长度固定

       执行复杂的数据处理,繁琐

       Collection 接口

            | – List 接口 

                    | – ArrayList

                    | – LinkedList

            | – Set  接口

                    | – HashSet

                    | – TreeSet

        Map 接口

             | – HashMap

             | – Treemap

        Iterator 接口

        Collections 工具类

LinkedList

         双向链表 , 圈的关系, 

         相邻节点互相引用,首尾节点互相引用

         只能访问第一位,两端效率高,越往中间效率越低

         没有容量限制,但是不能超出 int 范围

       

         方法

         add(数据); // 在末尾添加数据

         get(i);      // 获取指定位置数据

         remove(i); // 删除指定位置数据

         remove(数组); // 找到第一个相等数据删除

         size();  数量

         addFirst(数据);

         addLast();

         getFirdt();

         getLast();

         removeFirst();

         removeLast();

         iterator(); // 辅助创建迭代器对象, 对当前对象进行遍历

         

     

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,965
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781