Java_API和常用类

API

API(Application Programming Interface)
应用程序编程接口

常用类

Object类概述

类层次结构的根类
所有类都直接或者间接的继承自该类

构造方法
public Object()

Object类成员方法

public int hashCode()
public final Class getClass()
public String toString()
public boolean equals(Object obj)
protected void finalize()
protected Object clone()

Scanner类概述

JDK5以后用于获取用户的键盘输入

构造方法
public Scanner(InputStream source)

Scanner类成员方法

基本格式
hasNextXxx()  判断是否还有下一个输入项,其中Xxx可以是Int,Double等。如果需要判断是否包含下一个字符串,则可以省略Xxx
nextXxx()  获取下一个输入项。Xxx的含义和上个方法中的Xxx相同
默认情况下,Scanner使用空格,回车等作为分隔符
常用方法
public int nextInt()
public String nextLine()

String类概述

字符串是由多个字符组成的一串数据(字符序列)
字符串可以看成是字符数组

构造方法
public String()
public String(byte[] bytes)
public String(byte[] bytes,int offset,int length)
public String(char[] value)
public String(char[] value,int offset,int count)
public String(String original)

String类判断功能

boolean equals(Object obj)
boolean equalsIgnoreCase(String str)
boolean contains(String str)
boolean startsWith(String str)
boolean endsWith(String str)
boolean isEmpty()

String类的获取功能

int length()
char charAt(int index)
int indexOf(int ch)
int indexOf(String str)
int indexOf(int ch,int fromIndex)
int indexOf(String str,int fromIndex)
String substring(int start)
String substring(int start,int end)

String类的转换功能

byte[] getBytes()
char[] toCharArray()
static String valueOf(char[] chs)
static String valueOf(int i)
String toLowerCase()
String toUpperCase()
String concat(String str)

替换功能
String replace(char old,char new)
String replace(String old,String new)
去除字符串两空格	
String trim()
按字典顺序比较两个字符串  
int compareTo(String str)
int compareToIgnoreCase(String str) 

StringBuffer类概述

StringBuffer类概述
我们如果对字符串进行拼接操作,每次拼接,都会构建一个新的String对象,既耗时,又浪费空间。而StringBuffer就可以解决这个问题
线程安全的可变字符序列
StringBuffer和String的区别?

构造方法
public StringBuffer() 
public StringBuffer(int capacity)
public StringBuffer(String str)

StringBuffer类的成员方法

添加功能
public StringBuffer append(String str)
public StringBuffer insert(int offset,String str)
删除功能
public StringBuffer deleteCharAt(int index)
public StringBuffer delete(int start,int end)
替换功能
public StringBuffer replace(int start,int end,String str)
反转功能	
public StringBuffer reverse()
截取功能
public String substring(int start)
public String substring(int start,int end)
截取功能和前面几个功能的不同
返回值类型是String类型,本身没有发生改变

Arrays类概述及其常用方法

Arrays类概述
针对数组进行操作的工具类。
提供了排序,查找等功能。

成员方法
public static String toString(int[] a)
public static void sort(int[] a)
public static int binarySearch(int[] a,int key)

public static String toString(int[] a)

public static int binarySearch(int[] a,int key)

Integer类概述及其构造方法

Integer类概述
Integer 类在对象中包装了一个基本类型 int 的值
该类提供了多个方法,能在 int 类型和 String 类型之间互相转换,还提供了处理 int 类型时非常有用的其他一些常量和方法

构造方法
public Integer(int value)
public Integer(String s)

Integer类的成员方法

int类型和String类型的相互转换
int – String
String – int

public int intValue()
public static int parseInt(String s)
public static String toString(int i)
public static Integer valueOf(int i)
public static Integer valueOf(String s)

常用的基本进制转换

public static String toBinaryString(int i)
public static String toOctalString(int i)
public static String toHexString(int i)
十进制到其他进制
public static String toString(int i,int radix)
其他进制到十进制
public static int parseInt(String s,int radix)

Character类概述及其构造方法

Character类概述
Character 类在对象中包装一个基本类型 char 的值
此外,该类提供了几种方法,以确定字符的类别(小写字母,数字,等等),并将字符从大写转换成小写,反之亦然

构造方法
public Character(char value)

Character类的成员方法

public static boolean isUpperCase(char ch)
public static boolean isLowerCase(char ch)
public static boolean isDigit(char ch)
public static char toUpperCase(char ch)
public static char toLowerCase(char ch)

正则表达式

正则表达式:是指一个用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串。其实就是一种规则。

规则字符在java.util.regex Pattern类中
常见组成规则
字符
字符类
预定义字符类
边界匹配器
数量词

应用

判断功能
public boolean matches(String regex)
分割功能
public String[] split(String regex)
替换功能
public String replaceAll(String regex,String replacement)
获取功能
Pattern和Matcher类的使用
判断功能:
校验邮箱
分割功能:
我有如下一个字符串:”91 27 46 38 50”
请写代码实现最终输出结果是:”27 38 46 50 91”
替换功能:
论坛中不能出现数字字符,用*替换
获取功能:
获取由三个字符组成的单词

Math类概述及其成员方法

Math类概述
Math 类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。

成员方法
public static int abs(int a)
public static double ceil(double a)
public static double floor(double a)
public static int max(int a,int b) min自学
public static double pow(double a,double b)
public static double random()
public static int round(float a) 参数为double的自学
public static double sqrt(double a)

Random类概述及其构造方法

Random类概述
此类用于产生随机数
如果用相同的种子创建两个 Random 实例,则对每个实例进行相同的方法调用序列,它们将生成并返回相同的数字序列。

构造方法
public Random()
public Random(long seed)

成员方法

public int nextInt()
public int nextInt(int n)

System类概述及其成员方法

System类概述
System 类包含一些有用的类字段和方法。它不能被实例化。

成员方法

public static void gc()
public static void exit(int status)
public static long currentTimeMillis()
public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length)

BigInteger类概述及其构造方法

BigInteger类概述
可以让超过Integer范围内的数据进行运算

构造方法
public BigInteger(String val)

成员方法

public BigInteger add(BigInteger val)
public BigInteger subtract(BigInteger val)
public BigInteger multiply(BigInteger val)
public BigInteger divide(BigInteger val)
public BigInteger[] divideAndRemainder(BigInteger val)

BigDecimal类概述及其构造方法

由于在运算的时候,float类型和double很容易丢失精度,演示案例。所以,为了能精确的表示、计算浮点数,Java提供了BigDecimal
BigDecimal类概述
不可变的、任意精度的有符号十进制数。

构造方法
public BigDecimal(String val)

成员方法

public BigDecimal add(BigDecimal augend)
public BigDecimal subtract(BigDecimal subtrahend)
public BigDecimal multiply(BigDecimal multiplicand)
public BigDecimal divide(BigDecimal divisor)
public BigDecimal divide(BigDecimal divisor,int scale,int roundingMode)

Date类概述及其方法

Date类概述
类 Date 表示特定的瞬间,精确到毫秒。

构造方法
public Date()
public Date(long date)

成员方法

public long getTime()
public void setTime(long time)

DateFormat类概述及其方法

DateFormat类概述
DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间。
是抽象类,所以使用其子类SimpleDateFormat

SimpleDateFormat构造方法

public SimpleDateFormat()
public SimpleDateFormat(String pattern)

成员方法

public final String format(Date date)
public Date parse(String source)

Calendar类概述及其方法

Calendar类概述
Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等 日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法。

成员方法

public static Calendar getInstance()
public int get(int field)
public void add(int field,int amount)
public final void set(int year,int month,int date)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值