那里有個(gè)人做網(wǎng)站的網(wǎng)址推薦
文章目錄
- 一、集合概述
- 二、Collection
- 2.1 List接口
- 2.2 Set接口(不常用)
- 2.2.1 TreeSet
- 三、Map接口
- 四、Collections工具類
- 五、String
- 六、String類型轉(zhuǎn)換
- 6.1 基本數(shù)據(jù)類型
- 6.2 基本數(shù)據(jù)類型、包裝類 --> String
- 6.3 String與char[]
- 6.4 String與byte[]
一、集合概述
- Collection接口:單列數(shù)據(jù)
- List接口:元素有序、可重復(fù)的集合 “動(dòng)態(tài)數(shù)組”
- ArrayList、LinkedList、Vector
- Set接口:元素?zé)o序、不可重復(fù)的集合 “集合”
- HashSet(子類:LinkedHashSet)、TreeSet
- List接口:元素有序、可重復(fù)的集合 “動(dòng)態(tài)數(shù)組”
- Map接口:雙列數(shù)據(jù)
- HashMap、LinkedHashMap、TreeMap、Hashtable、Properties
二、Collection
需重寫equals()
- add(Objec tobj)
- addAll(Collection coll)
- int size()
- void clear()
- boolean isEmpty()
- boolean contains(Object obj)
- boolean containsAll(Collection c)
- boolean remove(Object obj)
- boolean removeAll(Collection coll)
- boolean retainAll(Collection c):把交集的結(jié)果存在當(dāng)前集合中,不影響c
- boolean equals(Object obj)
- Object[] toArray() :轉(zhuǎn)成對(duì)象數(shù)組
- hashCode():獲取集合對(duì)象的哈希值
- iterator() : :hasNext()、next()、remove()
2.1 List接口
- void add(intindex, Object ele)
- boolean addAll(int index, Collection eles)
- Object get(int index)
- int indexOf(Object obj):返回obj在集合中首次出現(xiàn)的位置
- int lastIndexOf(Object obj): 返回obj在當(dāng)前集合中末次出現(xiàn)的位置
- Object remove(int index):移除指定index位置的元素,并返回此元素
- Object set(int index, Object ele)
- List subList(int fromIndex, int toIndex)
2.2 Set接口(不常用)
Set需重寫hashCode()和equals()
HashSet(子類:LinkedHashSet)無(wú)額外方法,
2.2.1 TreeSet
Comparator comparator() 兩種排序方式:自然排序(實(shí)現(xiàn)Comparable接口) 和 定制排序(Comparator)
三、Map接口
Map中的key用Set來(lái)存放,不允許重復(fù),需重寫hashCode()和equals()方法。
- Object put(Object key,Object value)
- void putAll(Map m)
- Object remove(Object key
- void clear()
- Object get(Object key)
- boolean containsKey(Object key)
- boolean containsValue(Object value)
- int size()
- boolean isEmpty()
- boolean equals(Object obj)
- Set keySet()
- Collection values()
- Set entrySet()
四、Collections工具類
- reverse(List)
- shuffle(List)
- sort(List)
- sort(List,Comparator)
- swap(List,int, int)
- Object max(Collection)
- Object max(Collection,Comparator)
- Object min(Collection)
- Object min(Collection,Comparator)
- int frequency(Collection,Object)
- void copy(List dest,List src)
- boolean replaceAll(List list,Object oldVal,Object newVal)
五、String
- int length()
- char charAt(int index)
- boolean isEmpty()
- String toLowerCase()
- String toUpperCase()
- String trim()
- boolean equals(Object obj)
- boolean equals IgnoreCase(String anotherString)
- String concat(String str)
- int compareTo(String anotherString)
- String substring(int beginIndex)
- String substring(int beginIndex,int endIndex)
- boolean endsWith(String suffix)
- boolean startsWith(String prefix)
- boolean startsWith(String prefix, int toffset)
- boolean contains(CharSequence s)
- int indexOf(String str)
- int indexOf(String str, int fromIndex)
- int lastIndexOf(String str)
- int lastIndexOf(String str, int fromIndex)
- String replace(char oldChar, char newChar)
- String replace(CharSequence target, CharSequence replacement)
- String replaceAll(String regex, String replacement)
- String replaceFirst(String regex, String replacement)
- boolean matches(String regex):告知此字符串是否匹配給定的正則表達(dá)式
- String[] split(String regex)
- String[] split(String regex, int limit)
六、String類型轉(zhuǎn)換
6.1 基本數(shù)據(jù)類型
String --> 基本數(shù)據(jù)類型、包裝類:調(diào)用包裝類的靜態(tài)方法:parseXxx(str)
int num = Integer.parseInt(str1);
6.2 基本數(shù)據(jù)類型、包裝類 --> String
調(diào)用String重載的valueOf(xxx)
String str2 = String.valueOf(num);
6.3 String與char[]
String --> char[]:
調(diào)用String的toCharArray() char[] charArray = str1.toCharArray();
char[] --> String:
調(diào)用String的構(gòu)造器 String str2 = new String(arr);