基础掌握API

Object(祖宗类)

方法

说明

public String toString()

默认是返回当前对象在堆内存中的地址信息:类的全限名@内存地址

public Boolean equals(Object o)

默认是比较当前对象与另一对象的地址是否相同,相同返回true,不同返回false

Objects(工具类)

方法名

说明

public static boolean equals

(Object a,Object b) 

比较两个对象,底层先进行非空判断,从而可以避免空指针异常,再进行equals比较

public static boolean isNull

(Object o) 

判断变量是否为null ,为null返回true ,反之

System(系统类)

方法名

说明

public static void exit

(int status)

终止当前运行的 Java 虚拟机,非零(!0)表示异常终止,零(0)表示人为结束

public static long

currentTimeMillis()

返回当前系统的时间毫秒值形式

public static void arraycopy

(数据源数组,起始索引,目的地数组,起始索引, 拷贝个数)

数组拷贝

BigDecimal(大数据小数类)

构造器

说明

BigDecimal(String val)

将 BigDecimal 的十进制字符串表示形式转换为 BigDecimal

BigDecimal b = new BigDecimal("1000000.0001");//创建BigDecimal对象

方法

说明

public BigDecimal add

(BigDecimal b)

加法

public BigDecimal subtract

(BigDecimal b)

减法

public BigDecimal multiply

(BigDecimal b)

乘法

public BigDecimal divide

(BigDecimal b)

除法

public BigDecimal divide (另一个BigDecimal对象,精确几位,取舍模式)

除法

double d = b.doubleValue();//转换为double对象(可能不准确超出double范围)

BigInteger (大数据整数类)

构造器

说明

BigInteger(String val)

将 BigInteger 的十进制字符串表示形式转换为 BigInteger

BigInteger b = new BigInteger("1000000.0001");//创建BigInteger对象

方法

说明

public BigInteger add(对象)

加法

public BigInteger subtract(对象)

减法

public BigInteger multiply(对象)

乘法

public BigInteger divide(对象)

除法,除不尽取整,抹去小数

double d = b.doubleValue();//转换为double对象(可能不准确超出double范围)

Sting(字符串类)

构造器

说明

public String()

创建一个空白字符串对象,不含有任何内容

public String(String s)

根据传入的字符串内容,来创建字符串对象

public String(char[] c)

根据字符数组的内容,来创建字符串对象

public String(byte[] c)

根据字节数组的内容,来创建字符串对象

方法

说明

public boolean equals 

(Object o)

将此字符串与指定对象进行比较。只关心字符内容是否一致

public boolean equalsIgnoreCase

(String o)

将此字符串与指定对象进行比较,忽略大小写比较字符串。只关心字符内容是否一致

public int length​()

返回此字符串的长度

public char charAt​(int index)

获取某个索引位置处的字符

public char[] toCharArray​()

将当前字符串转换成字符数组返回

public String substring

(int beginIndex, int endIndex)

根据开始和结束索引进行截取,得到新的字符串(包前不包后)

public String substring

(int beginIndex)

从传入的索引处截取,截取到末尾,得到新的字符串

public String[] split

(String regex)

根据传入的规则切割字符串,得到字符串数组返回

public String replace

(CharSequence target,

 CharSequence replacement)

使用新值,将字符串中的旧值替换,得到新的字符串

StingBuilder(可变字符串类)

构造器

说明

public StringBuilder()

创建一个空白的可变的字符串对象,不包含任何内容

public StringBuilder

(String s)

创建一个指定字符串内容的可变字符串对象

方法

说明

public StringBuilder append

(Object o)

添加数据并返回StringBuilder对象本身

public StringBuilder reverse()

将对象的内容反转

public int length()

返回对象内容长度

public String toString()

通过toString()就可以实现把StringBuilder转换为String

Math(数学类)

方法名

说明

public static int abs​(int a)

获取参数绝对值

public static double ceil

(double a)

向上取整

public static double floor

(double a)

向下取整

public static int round​(float a)

四舍五入

public static int max

​(int a,int b)

获取两个int值中的较大值

public static double pow

​(double a,double b)

返回a的b次幂的值

public static double random​()

返回值为double的随机值,范围[0.0,1.0)

Arrays(数组工具类)

方法名

说明

public static void sort(int[] a)

升序排序

public static int binarySearch

(int[] a,int key)

二分查找(前提已经升序排好)

public static String toString

(int[] a)

按照[元素1,元素2...]格式输出数组元素

Date(日期类)

构造器

说明

public Date()

创建一个Date对象,代表的是系统当前此刻日期时间

public Date(long time)

把时间毫秒值转换成Date日期对象

方法

说明

public long getTime()

返回从1970年1月1日00:00:00走到此刻的总的毫秒数(中国东八区8:00)

public void setTime(long time)

设置日期对象的时间为当前时间毫秒值对应的时间

SimpleDateFormat(日期格式类)

构造器

说明

public SimpleDateFormat

(String pattern)

构造一个SimpleDateFormat,使用指定的格式

方法

说明

public final String format

(Date date)

将日期格式化成日期/时间字符串

public final String format

(Object time)

将时间毫秒值式化成日期/时间字符串

public Date parse

(String source)

从给定字符串的开始解析文本以生成日期

Calendar(日历类)

方法名(创建对象)

说明

public static Calendar

getInstance()

获取当前日历对象

Calendar calendar = Calendar.getInstance();//创建日历对象

方法

说明

public int get(int field)

取日期中的某个字段信息

public void set

(int field,int value)

修改日历的某个字段信息

public void add

(int field,int amount)

为某个字段增加/减少指定的值

public final Date getTime()

拿到此刻日期对象

public long getTimeInMillis()

拿到此刻时间毫秒值

包装类

基本类型

引用类型(包装类)

byte

Byte

short

Short

int

Integer

long

Long

float

Float

double

Double

char

Character

boolean

Boolean

对象创建

说明

public Integer(int value)

int参数value,转换成Integer对象

public Integer(String value)

String参数value,转换成Integer对象

public static Integer valueOf

(int i)

用方法,把参数int类型的i转换成Integer类型并返回

public static Integer valueOf

(String i)

用方法,把参数String类型的i转换成

Integer类型并返回

包装类取值范围

常量

说明

以int为例

public static final int  

MAX_VALUE = 0x7f ff ff ff;

Integer调用常量

Integer.MAX_VALUE

public static final int  

MIN_VALUE = 0x80000000;

Integer调用常量

Integer.MIN_VALUE

进制转换

方法

说明

Integer.toBinaryString(num)

转二进制

Integer.toOctalString(num)

转八进制

Integer.toHexString(num)

转十六进制

基本类型转换成String

数据转换

说明

以int类为例

基本类型int数据  + ""

借助+进行字符串拼接

String strNum = num + ""

public static String valueOf

(int i)

把方法参数int数据i,转换成String类型并返回

String s = String.valueOf(num);

public static String toString

(int i)

把方法参数int数据i,调用toString转换成String类型并返回

String s = Integer.toString(num);

String解析成基本类型

数据转换

说明

public static xxx parseXxx

(String str)

用方法把参数String数据str转换成

xxx类型的数据

以int类为例

public static int parseInt

(String str)

用方法把参数String数据str转换成

int类型的数据

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值