String類
- equals 將此String與另一個(gè)String進(jìn)行比較
- equalsIgnoreCase 將此String與另一個(gè)String進(jìn)行比較不考慮大小寫
- concat 將指定的字符串連接到該字符串的末尾
- charAt(i) 獲取指定i所在位置的字符
- indexOf("i") 獲取i所在位子的角標(biāo)炕倘,如果不存在i,則返回-1矮男;
- substring(i) 從start開始截取到i位子的值
- substring(i忆家,j) 從i開始截取到j(luò)位子的值檬某, 左閉右開U饽选T冶颉A芽选顺囊!
- String s = "helloworld";
- toCharArray 字符轉(zhuǎn)化為字符數(shù)組
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
System.out.println(chars[i]);
}
- getBytes 字符轉(zhuǎn)化為字節(jié)數(shù)組
byte[] bytes = s.getBytes();
for (int i = 0; i <bytes.length ; i++) {
System.out.println(bytes[i]);
} - replace("hh","HH") hh替換為HH
- split("h") 從h開始分割
Arrays
- Arrays.toString()返回?cái)?shù)組內(nèi)容的字符串表示形式
- Arrays.sort(arr)對指定的int類型的數(shù)組進(jìn)行升序排序
Math類
- Math.abs()絕對值
- Math.ceil()返回值大于等于參數(shù)的最小整數(shù)
- Math.floor()返回值小于等于參數(shù)的最小整數(shù)
- Math.round()四舍五入
System類
- System.currentTimeMIllis()獲取當(dāng)前系統(tǒng)時(shí)間與1970年1月1日00點(diǎn)00分之間的毫秒值
- System.arraycopy將數(shù)組中指定的數(shù)據(jù)拷貝到拎一個(gè)數(shù)組中
StingBuilder類
- String對象為不可變
- StringBuilder builder = new StringBuilder();
-StringBuilder builder1 = builder.append("hello");
StringBuilder可以添加任何類型
public String toString(){}
通過toString方法, StringBuilder對象將會轉(zhuǎn)換為不可變的String對象
Calendar類(抽象類)
- Calendar calendar = Calendar.getInstance();創(chuàng)建Calendar對象
- calendar.get()獲取日歷字段中的值
- calendar.set()將日歷中的字段設(shè)置為給定的值
- calendar.add(Caelndar.YEAR,2)為給定的日歷添加或減去指定時(shí)間量
- Calendar calendar=Calendar.getInstance()蕉拢;
- Date date=calendar.getTime()特碳;
表示此Calendar時(shí)間值(從歷元到現(xiàn)在的毫秒偏移量)的Date 對象。 - SimpleDateFormat sdf=new SimpleDateFormat(格式)晕换;
- Date date=sdf.parse(String類型)午乓;
- 將String類型時(shí)間對象轉(zhuǎn)換為Date類型時(shí)間對象
DateFormat df2 = new SimpleDateFormat(String類型);
String str2 = df2.format(date);
- 將Date時(shí)間對象轉(zhuǎn)換為String類型時(shí)間對象
new Date(0L)當(dāng)前的毫秒值轉(zhuǎn)化成日期對象
new Date().getTime()把日期對象轉(zhuǎn)換為對應(yīng)的時(shí)間毫秒值
Collection 集合
- collection.add()把給定的元素添加到集合中
- collection.clear()清空集合中的所有元素
- collection.remove()把給定對象從集合中刪除
- collection.contains()判斷當(dāng)前集合是否為空
- collection.isEmpty()判斷集合是否為空
- collection.size()輸出集合中元素的個(gè)數(shù)
- Object[] objects = coll.toArray()把集合中的元素返回為Object[]數(shù)組
- Collection.shuffle() 隨機(jī)打亂集合中元素的順序
- Collection.addAll()(結(jié)合名,集合內(nèi)容)全部添加
Map集合
- map.put()把指定的鍵和值添加到集合中
- map.get()根據(jù)鍵獲取相對應(yīng)的值
- map.remove()根據(jù)鍵刪除對應(yīng)的值
- map.containsKey()判斷集合是否包含指定的鍵-
- Set<String> keys = map.keySet();獲取所有鍵,存儲到set結(jié)合中
- public Set<Map.Entry<K,V>> entrySet()届巩;獲取所有的鍵值對的set集合
- K getKey(); 獲取Entry對象中的鍵
- V getValue();獲取Entry對象中的值