String 类
构造方法
String(byte[] bytes
)
把一个字节数组转换成字符串
String(byte[] bytes
, int index
, int length
)
把一个字节数组的一部分转换成字符串
String(char[] value
)
把一个字符数组转换成字符串
String(char[] value
, int index
, int length
)
把一个字符数组的一部分转换成字符串
判断功能
**boolean equals(Object obj
) :
判断两个字符串是否相同 区分大小写
boolean equalsIgnoreCase(String str
) :
判断两个字符串是否相同 不区分大小写
**boolean contains(String str
):
判断大串中是否包含小串
**boolean startsWith(String str
):
判断字符串是否是以指定字符串开头
**boolean endsWith(String str
):
判断字符串是否是以指定字符串结尾
**boolean isEmpty():
判断字符串是否为空
获取功能
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
)
截取字符串
,从指定位置开始
,到指定位置结束
,返回一个新的字符串
(源字符串不变
)
转换功能
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 oldChar
, char newChar
)
用新的字符去替换旧的字符
String
replace(String oldString
, String newString
)
用新的字符串去替换旧的字符串
String
trim()
取出两端空格
.
int compareTo(String str
)
按照字典顺序比较两个字符串
,如果相同则返回
0.
public String
[] split(String regex
)
按照指定标记去分割字符串
,返回字符串数组
String类中
public String
replaceAll(String regex
,String replacement
)
替换指定字符串中所有符合正则规则的字符串
------------------------------------------------------------------------------------------------------------------------------------
StringBuffer
构造方法
StringBuffer()
创建StringBuffer的对象
,默认容量
16
StringBuffer( int capacity
)
通过带参构造创建指定容量的对象
StringBuffer( String str
)
把一个字符串转换成 StringBuffer
StringBuffer sb
= "22".;
String s
= "22".;
public int capacity():获取理论容量
public int length(): 获取实际长度
.
public StringBuffer append
( int i
)
向末尾追加数据
public StringBuffer insert
( int index
, String i
)
向指定索引处插入数据
StringBuffer deleteCharAt
( int index
)
删除指定索引位置的字符
StringBuffer delete
( int start
, int end
)
删除指定区间的数据
StringBuffer
replace(int start
, int end
, String str
)
从指定索引开始到指定索引处
,使用一个新的字符串替换
(用字符串替换区间值
)
StringBuffer
reverse()
反转
String
substring(int start
)
从指定位置截取到末尾
(返回截取后的字符串
)
String
substring(int start
, int end
)
截取指定区间位置的数据
(返回截取后的字符串
)
----------------------------------------------------------------------------------------------------------------------------------------------
Arrays工具类
public static String
toString( int[] a
)
把一个整形数组转换成字符串
public static void sort( int[] a
)
对数组进行排序
public static int binarySearch
( int[] a
, int key
)
对数组进行二分查找
----------------------------------------------------------------------------------------------------------------------------------------------
Integer
.parseInt( String s
);
把一个String类型的整数转换成
int类型
----------------------------------------------------------------------------------------------------------------------------------------------
Math 类方法
A:Math
.abs(参数类型 形式参数
)
绝对值
B:Math
.ceil(-18.8);
向上取整
C:Math
.floor(12.3)
向下取整
D:Math
.round(12.6);
四舍五入
E:Math
.random();
获取
0.0-1.0的随机数
,包含
0.0不包含
1.0
F:Math
.max(12,53);
取大值
G:Math
.min(11,66);
取小值
----------------------------------------------------------------------------------------
Random 类 方法
public Random()
根据默认种子创建对象
(当前时间的纳秒值
)
public Random(long seed
)
通过固定的种子创建对象
B
:成员方法
public int nextInt()
获取一个
int范围内的随机数
public int nextInt(int n
)
生成
0-n之间的随机数
---------------------------------------------------------------------------------------------------------------------------------------------
System 类
public static void gc()
调用垃圾回收方法
public static void exit(int status
)
退出java虚拟机
public static long currentTimeMillis()
获取当前时间的毫秒值
(我们可以使用它来测试程序的执行时间
.)
pubiic
static void arraycopy(Object src
, int srcPos
, Object dest
, int destPos
, int length
)
复制数组
---------------------------------------------------------------------------------------------------------------------------------------------
Date 类
1、
Date()
获取当前系统时间
2、
Date( long time
)
根据给定毫秒值获取时间对象
3、
public long getTime();
获取当前时间的毫秒值
4、
void setTime();
设置当前时间的毫秒值
--------------------------------------------------------------------------------------------------------------------------------------------
SimpleDateFormat 类
public Date
parse(String source
)
把字符串日期转换成Date对象
public final String
format(Date date
)
把Date对象转换成既定样式的字符串
------------------------------------------------------------------------------------------------------------------------------------------
Calendar 类
1、
public final void set
( int year
, int month
, int date
);
给指定的字段设置 年
, 月
, 日
2、
public abstract void add
( int field
, int amount
);
给指定的日历字段
,增加或减少相应的日期