package map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class MapTypeTest {
public static void main(String[] args) {
// HashMap:无序、线程不安全
// Map map = new HashMap<>();
// Hashtable:无序、线程安全、性能差
// Map map = new Hashtable();
// LinkedHashMap:有序、线程不安全
// Map map = new LinkedHashMap();
// TreeMap:有序
// Map map = new TreeMap();
// ConcurrentHashMap:线程安全、性能好
Map map = new ConcurrentHashMap();
map.put("1", "1");
map.put("2", "2");
map.put("3", "3");
map.put("4", "4");
map.put("5", "5");
map.put("6", "6");
map.put("7", "7");
map.put("8", "8");
map.put("9", "9");
map.put("10", "10");
map.put("11", "11");
map.put("12", "12");
map.put("13", "13");
map.put("14", "14");
map.put("15", "15");
map.put("16", "16");
map.put("17", "17");
map.put("18", "18");
map.put("19", "19");
map.put("20", "20");
map.put("21", "21");
map.put("22", "22");
Set set = map.keySet();
set.forEach(System.out::println);
}
}
Java Map特性学习
最新推荐文章于 2024-04-17 09:00:37 发布