重学java 36.API 总结

忙碌,让我感到我活着

                —— 24.5.13

API总结

一、数学相关类

1.Math类

1.概述

        数学工具类

2.特点

        a.构造私有
        b.方法静态        

3.使用

        类名直接调用

4.方法

        static int abs(int a) —— 求参数的绝对值
        static double ceil(double a) —— 向上取整
        static double floor(double a) —— 向下取整
        static long round(double a) —— 四舍五入
        static int max(int a, int b) —— 求两个数之间的较大
        static int min(int a, int b) —— 求两个数之间的较小

2.BigInterger

1.概述

        处理超大整数的类

2.构造

        BigInteger(String s)

3.方法

        BigInteger add(BigInteger val) —— 返回其值为(this + val) 的 BigInteger
        BigInteger subtract(BigInteger val) —— 返回其值为(this - val)的BigInteger
        BigInteger multiply(BigInteger val) —— 返回其值为(this * val) 的 BigInteger
        BigInteger divide(BigInteger val) —— 返回其值为(this / val) 的 BigInteger

3.BigDecimal

1.概述

        解决用float和double直接做运算而产生的精度损失问题的类

2.构造

        BigDecimal(String s)

3.方法

        static BigDecimal valueOf(double val) —— 此方法初始化小数时可以传入double型数据
        BigDecimal add(BigDecimal val) —— 返回其值为(this + val) 的 BigDecimal
        BigDecimal subtract(BigDecimal val) —— 返回其值为(this-val)的BigDecimal
        BigDecimal multiply(BigDecimal val) —— 返回其值为(this*val)的BigDecimal
        BigDecimal divide(BigDecimal val) —— 返回其值为(this/val)的BigDecimal
        divide(BigDecimal divisor, int scale.RoundingMode roundingMode)

                divisor:代表除号后面的数据
                scale:保留几位小数
                roundingMode:取舍方式:

                        UP:向上加1

                        DOWN:直接舍去
                        HALF_UP:四舍五入

二、日期相关类 

1.Date日期类

1.概述

        代表日期

2.构造

        Date() —— 获取当前系统时间
        Date(long time) —— 获取指定时间,传递亳秒值,从时间原点开始算

3.方法

        a.void setTime(long time) —— 设置时间,传递毫秒值,从时间原点开始算
        b.long getTime() —— 获取时间,返回毫秒值

2.Calender日历类

1.概述

        代表日历类

2,获取

        static Calendar getlnstance()

3.方法

        int get(int field) —— 返回给定日历字段的值
        void set(int field,int value) —— 将给定的日历字段设置为指定的值
        void add(int field, int amount) —— 根据目历的规则,为给定的日历字段添加或者减去指定的时间量
        Date getTime() —— 将Calendar转成Date对象

3.SimpleDaterormat日期格式化类

1.概述

        将日期按照指定格式格式化

2.构造

        simpleDateFormat(String pattern)

3.方法

        String format(Date date) —— 将Date对象按照指定的格式转成Sting
        Date parse(String source) —— 将符合日期格式的字符串转成Date对象

4.jdk8新日期类

1.LocalDate(表示年月日)

         a.获取

                static LocalDate now0 —— 创建LocalDate对象
                static LocalDate of(int year, int month, intdayOfMonth) —— 创建LocalDate对象,设置年月日

2.LocalDateTime(表示年月日时分秒)

        a.获取
                static LocalDateTime now() —— 创建LocalDateTime对象
                static LocalDateTime of(int year. Monthmonth.int dayOfMonth, int hour, intminute,int second)创建LocalDateTime对象,设置年月日时分秒

3.获取日期字段

        int getYear() —— 获取年份

        int getMonthValue() —— 获取月份
        int getDayOfMonth() —— 获取月中的第几天

4.设置字段

        LocalDate withYear(int year):设置年份
        LocalDate withMonth(int mnonth):设置月份
        LocalDate withDayOfMonth(int day):设置月中的天数

5.日期字段偏移

        设置日期字段的偏移量,方法名plus开头,向后偏移
        设置日期字段的偏移量,方法名minus开头,向前偏移

6.计算日期偏差

        Period

                a.方法

                        static Period between(LocalDated1,LocalDate d2):计算两个日期之间的差值
                        getYears() —— 获取相差的年
                        getMonths() —— 获取相差的月
                        getDays() —— 获取相差的天

        Duration

                a.方法
                        static Duraton between(TemporalstartInclusive,Temporal endExclusive) —— 计算时间差
                        toDays():获取相差天数
                        toHours():获取相差小时
                        toMinutes():获取相差分钟
                        toMillis():获取相差秒(毫秒)

7.日期格式化

        DateTimeFormater日期格式化类

                1.概述 

                         将日期按照指定格式格式化
                2.构造

                        SimpleDateFormat(String pattern)
                3.方法
                        String format(Date date) —— 将Date对象按照指定的格式转成String
                        Date parse(String source) —— 将符合日期格式的字符串转成Date对象

三、工具类

1.System

1.概述

        系统相关类

2.特点

        a.构造私有
        b.方法静态

3.使用

        类名直接调用

4.方法

        static long currentTimeMillis() —— 返回以毫秒为单位的当前时间,可以测效率

        static void exit(int status)-终止当前正在运行的 Java 虚拟机

        static void arraycopy(Object src, int srcPos,Object dest,int destPos,int length) —— 数组复制
                src:源数组

                srcPos:从源数组的哪个索引开始复制

                dest:目标数组
                destPos:从目标数组哪个索引开始粘贴
                length:复制多少个元素

2.Arrays

1.概述

        数组工具类

2.特点

        a.构造私有
        b.方法静态

3.使用

        类名直接调用

4.方法

        static String toString(int[] a) —— 按照格式打印数组元素[元素1,元素2,..]
        static void sort(int[]a) —— 升序排序
        static int binarySearch(int[] a, int key) —— 二分査找(前提是升序)
        static int[] copyOf(int[] original, int newLength) —— 数组扩容

四、包装类

1.概述

        基本类型对应的类,叫做包装类

2.基本类型和包装之间的对应

3.构造

        Integer(int value)
        Integer(string s) s必须是数字形式

4.装箱拆箱

        a.装箱(将基本类型转成包装类)

                static Integer valueOf(int i)
                static Integer valueOf(String s)
        b.拆箱(将包装类转成基本类型)

                int intValue();

5.基本类型和String之间转换

        a.基本类型转String

                static String valueOf(int i)

                +""

        b.String转基本类型

6.标准JavaBean

        开发中需要将基本类型的属性定义成包装类型

  • 29
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值