list
HashSetDemo
/**
* @qvthor liuwenzheng
* @date 2021/5/8 9:16
*/
public class HashSetDemo {
public static void main(String[] args) {
HashSet<String>set = new HashSet<>(); // <> 鉆石語(yǔ)法
set.add("111");
set.add("xxx");
set.add("上顯");
set.add("333");
System.out.println(set);
set.remove("xxx"); // 根據(jù)內(nèi)容移除
System.out.println(set);
int size = set.size();
boolean empty = set.isEmpty(); //判斷是否為空
System.out.println(size);
System.out.println(empty);
set.clear(); //清楚
System.out.println(set);
}
}
TreeSetDemo
/**
* @qvthor liuwenzheng
* @date 2021/5/8 9:26
*/
public class TreeSetDemo {
public static void main(String[] args) {
TreeSet<String> set = new TreeSet<>();
set.add("111");
set.add("222");
set.add("地理");
set.add("化學(xué)");
set.add("abc");
set.add("efg");
System.out.println(set);
}
}
HashMapDemo
/**
* @qvthor liuwenzheng
* @date 2021/5/8 10:06
*/
public class HashMapDemo {
public static void main(String[] args) {
HashMap<String, String> map = new HashMap<>(); //DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 默認(rèn)的初始值為16
map.put("henan","河南"); //entry 實(shí)例
map.put("hebei","河北");
map.put("hubei", "湖北");
map.put("hubei", "湖北1"); //鍵重復(fù)會(huì)覆蓋掉原有的值
map.put("null","空1");
map.put(null,"空2");
System.out.println(map);
for (Map.Entry<String,String> m : map.entrySet()){
System.out.println(m);
}
for (String k : map.keySet()){
System.out.println(k + "=" + map.get(k));
}
for (String v : map.values()){
System.out.println(v);
}
}
}
//DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 默認(rèn)的初始值為16
//DEFAULT_LOAD_FACTOR = 0.75f; 當(dāng)體內(nèi)容量達(dá)到全部的百分之75的時(shí)候直接擴(kuò)容
//TREEIFY_THRESHOLD = 8; 當(dāng)長(zhǎng)度為8的時(shí)候樹(shù)化
//UNTREEIFY_THRESHOLD = 6; 當(dāng)長(zhǎng)度為6的時(shí)候 退化為數(shù)組
//MAXIMUM_CAPACITY = 1 << 30; 默認(rèn)的最大 = 2的30次方
TrueMapDemo
/**
* @qvthor liuwenzheng
* @date 2021/5/8 11:03
*/
public class TrueMapDemo {
public static <TrueMap> void main(String[] args) {
TreeMap<String, String> map = new TreeMap<>(); //DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 默認(rèn)的初始值為16
map.put("henan","河南"); //entry 實(shí)例
map.put("hebei","河北");
map.put("hubei", "湖北");
map.put("hubei", "湖北1"); //鍵重復(fù)會(huì)覆蓋掉原有的值
map.put("null","空1");
map.put(null,"空2");
System.out.println(map);
for (Map.Entry<String,String> m : map.entrySet()){
System.out.println(m);
}
for (String k : map.keySet()){
System.out.println(k + "=" + map.get(k));
}
for (String v : map.values()){
System.out.println(v);
}
}
}
//DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 默認(rèn)的初始值為16
//DEFAULT_LOAD_FACTOR = 0.75f; 當(dāng)體內(nèi)容量達(dá)到全部的百分之75的時(shí)候直接擴(kuò)容
//TREEIFY_THRESHOLD = 8; 當(dāng)長(zhǎng)度為8的時(shí)候樹(shù)化
//UNTREEIFY_THRESHOLD = 6; 當(dāng)長(zhǎng)度為6的時(shí)候 退化為數(shù)組
//MAXIMUM_CAPACITY = 1 << 30; 默認(rèn)的最大 = 2的30次方