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ò)位子的值辟宗, 左閉右開>粽浴!2雌辍空幻!
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)對(duì)指定的int類型的數(shù)組進(jìn)行升序排序
Math類
- Math.abs()絕對(duì)值
- 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對(duì)象為不可變
- StringBuilder builder = new StringBuilder();
- StringBuilder builder1 = builder.append("hello");
- StringBuilder可以添加任何類型
- public String toString(){}
- 通過toString方法, StringBuilder對(duì)象將會(huì)轉(zhuǎn)換為不可變的String對(duì)象
Calendar類(抽象類)
- Calendar calendar = Calendar.getInstance();創(chuàng)建Calendar對(duì)象
-
calendar.get()獲取日歷字段中的值
- calendar.set()將日歷中的字段設(shè)置為給定的值
- calendar.add(Caelndar.YEAR,2)為給定的日歷添加或減去指定時(shí)間量
- Calendar calendar=Calendar.getInstance()容客;
Date date=calendar.getTime()秕铛;
表示此Calendar時(shí)間值(從歷元到現(xiàn)在的毫秒偏移量)的Date 對(duì)象。 - SimpleDateFormat sdf=new SimpleDateFormat(格式)缩挑;
Date date=sdf.parse(String類型)但两;
將String類型時(shí)間對(duì)象轉(zhuǎn)換為Date類型時(shí)間對(duì)象 - DateFormat df2 = new SimpleDateFormat(String類型);
String str2 = df2.format(date);
將Date時(shí)間對(duì)象轉(zhuǎn)換為String類型時(shí)間對(duì)象 - new Date(0L)當(dāng)前的毫秒值轉(zhuǎn)化成日期對(duì)象
- new Date().getTime()把日期對(duì)象轉(zhuǎn)換為對(duì)應(yīng)的時(shí)間毫秒值
Collection 集合
- collection.add()把給定的元素添加到集合中
- collection.clear()清空集合中的所有元素
- collection.remove()把給定對(duì)象從集合中刪除
- collection.contains()判斷當(dāng)前集合是否為空
- collection.isEmpty()判斷集合是否為空
- collection.size()輸出集合中元素的個(gè)數(shù)
- Collections.shuffle();隨機(jī)打亂集合的內(nèi)容的順序.
- Collection.addAll(結(jié)合名,集合內(nèi)容)全部添加
- Collection.sort() 對(duì)集合進(jìn)行排序
- Object[] objects = coll.toArray()把集合中的元素返回為Object[]數(shù)組
Map集合
- map.put()把指定的鍵和值添加到集合中
- map.get()根據(jù)鍵獲取相對(duì)應(yīng)的值
- map.remove()根據(jù)鍵刪除對(duì)應(yīng)的值
- map.containsKey()判斷集合是否包含指定的鍵
- Collection<String> values=map.values();
System.out.println(values);
把集合中的值進(jìn)行遍歷 - Set<String> keys = map.keySet();獲取所有鍵,存儲(chǔ)到set結(jié)合中
- public Set<Map.Entry<K,V>> entrySet()供置;獲取所有的鍵值對(duì)的set集合
- K getKey(); 獲取Entry對(duì)象中的鍵
- V getValue();獲取Entry對(duì)象中的值