day18目录:

Map集合
HashMap和Hashtable的区别
Collections(集合工具类)
集合练习
模拟斗地主(洗牌,发牌,看牌)

18.01_集合框架(Map集合概述和特点)(理解)

A: 需求:   根据学号获取学生姓名B:Map接口概述查看API可以知道:将键映射到值的对象一个映射不能包含重复的键每个键最多只能映射到一个值
C:Map接口和Collection接口的不同Map是双列的,Collection是单列的Map的键唯一,Collection的子体系Set是唯一的Map集合的数据结构针对键有效,跟值无关;Collection集合的数据结构是针对元素有效
public class MyTest {public static void main(String[] args) {/*  A:案例演示:需求:统计字符串中每个字符出现的次数"aababcabcdabcde", 获取字符串中每一个字母出现的次数要求结果:a(5) b(4) c(3) d(2) e(1)a(5) b(4) c(3) d(2) e(1)a-----5b-----4c-----3d-----2e-----1我们观察发现 这是一种 键值对应关系的数据对于这种数据我们可以采用双列集合存储集合遍历双列集合,拼接字符串。难点在于我们怎么统计字符出现的个数,然后存到集合中*/HashMap<Character, Integer> hm = new HashMap<>();Scanner sc = new Scanner(System.in);//请输入一段字符串System.out.println("请输入一段字符串");String str = sc.nextLine();//"aababcabcdabcde" 统计字符串中每个字符出现的次数,然后放到集合中// char[] chars = str.toCharArray();//遍历字符串for (int i = 0; i < str.length(); i++) {char ch = str.charAt(i);//判断这个键是不是第一次出现,如果不是,我就存进去,值给个1if (!hm.containsKey(ch)) {hm.put(ch, 1);  //a----1} else {//我应该获取出上一次的值,累加一次,再存进去,键相同,值覆盖Integer value = hm.get(ch);value++;//键相同,值覆盖hm.put(ch, value);}}//遍历集合拼接字符串StringBuilder sb = new StringBuilder();Set<Map.Entry<Character, Integer>> entries = hm.entrySet();for (Map.Entry<Character, Integer> entry : entries) {Character key = entry.getKey();Integer value = entry.getValue();// a(5) b(4) c(3) d(2) e(1)sb.append(key).append(" ").append("(").append(value).append(")");}String s = sb.toString();System.out.println(s);}
}
public class MyTest {public static void main(String[] args) {//我们生活中会经常遇到如下数据//key-----value// s001-----张三// s002-----李四// s003------王五ArrayList<String> list = new ArrayList<>();list.add("s001-----张三");list.add("s002-----李四");list.add("s003------王五");String[] split = list.get(0).split("[-]+");System.out.println(split[0]);System.out.println(split[1]);/** 对于这种键值映射(一个键映射一个值)关系的数据,Java为了我们更加方便的去操作 key=value形式的数据* 给我们提供了另外一种容器,叫做Map集合。***** */}
}

18.02_集合框架(Map集合的功能概述)(掌握)

A:Map集合的功能概述a:添加功能 V put(K key,V value):添加元素。这个其实还有另一个功能?替换如果键是第一次存储,就直接存储元素,返回null如果键不是第一次存在,就用值把以前的值替换掉,返回以前的值
public class MyTest2 {public static void main(String[] args) {//所有的双列集合的数据结构,只跟键有关,跟值没有关系。//HashMap 键的数据结构是哈希表,键唯一,键无序,键相同值就会覆盖HashMap<String, String> hashMap = new HashMap<>();//第一次存储键时,返回中时nullString s = hashMap.put("文章", "马伊琍");System.out.println(s);//键相同值覆盖。再次存储键相同的数据,返回的时上一次这个键对应的旧值。String s1 = hashMap.put("文章", "姚笛");System.out.println(s1);hashMap.put("王宝强", "蓉儿");hashMap.put("贾乃亮", "李小璐");hashMap.put("陈羽凡", "白百合");hashMap.put("陈思成", "佟丽亚");hashMap.put("大郎", "金莲");System.out.println(hashMap);}
}
public class MyTest3 {public static void main(String[] args) {//键是String类型 值 是 Student//所有的双列集合的数据结构,只跟键有关,跟值没有关系。HashMap<String, Student> hashMap = new HashMap<>();hashMap.put("s001", new Student("张三", 23));hashMap.put("s001", new Student("张三", 23));hashMap.put("s001", new Student("王老虎", 25));hashMap.put("s002", new Student("李四", 24));hashMap.put("s003", new Student("王五", 25));System.out.println(hashMap);}
}
public class MyTest4 {public static void main(String[] args) {//键是Student 类型,值是String//键是唯一 所有的双列集合的数据结构,只跟键有关,跟值没有关系。//键的数据结构是哈希表,你要保证键的唯一性,是靠键重写hashCode和equals方法,如果不重写,则无法保证。//HashSet<Student> students = new HashSet<>();//students.add(new Student("张三", 23));HashMap<Student, String> hashMap = new HashMap<>();hashMap.put(new Student("张三", 23), "s001");hashMap.put(new Student("张三", 23), "s001");hashMap.put(new Student("王老虎", 25), "s001");hashMap.put(new Student("李四", 24), "s002");hashMap.put(new Student("王五", 25), "s003");System.out.println(hashMap);}
}
    private String name;private int age;public Student() {}public Student(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}@Overridepublic boolean equals(Object o) {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;Student student = (Student) o;return age == student.age &&Objects.equals(name, student.name);}@Overridepublic int hashCode() {return Objects.hash(name, age);}
}
 b:删除功能void clear():移除所有的键值对元素V remove(Object key):根据键删除键值对元素,并把值返回c:判断功能boolean containsKey(Object key):判断集合是否包含指定的键boolean containsValue(Object value):判断集合是否包含指定的值boolean isEmpty():判断集合是否为空d:获取功能Set<Map.Entry<K,V>> entrySet(): 返回一个键值对的Set集合V get(Object key):根据键获取值Set<K> keySet():获取集合中所有键的集合Collection<V> values():获取集合中所有值的集合e:长度功能int size():返回集合中的键值对的对数

18.03_集合框架(Map集合的基本功能测试)(掌握)

A:案例演示Map集合的基本功能V put(K key,V value)//键相同 值覆盖  V remove(Object key)void clear()boolean containsKey(Object key)boolean containsValue(Object value)boolean isEmpty()int size()
public class MyTest2 {public static void main(String[] args) {HashMap<String, String> hashMap = new HashMap<>();hashMap.put("文章", "马伊琍");hashMap.put("王宝强", "蓉儿");hashMap.put("贾乃亮", "李小璐");hashMap.put("陈羽凡", "白百合");hashMap.put("陈思成", "佟丽亚");hashMap.put("大郎", "金莲");System.out.println(hashMap.containsKey("文章"));//trueSystem.out.println(hashMap.containsValue("aaa"));//falsehashMap.clear();System.out.println(hashMap.isEmpty());//true}
}

18.04_集合框架(Map集合的获取功能测试)(掌握)

A:案例演示V get(Object key)Set<K> keySet()Collection<V> values()

18.05_集合框架(Map集合的遍历之键找值)(掌握)

A:键找值思路:获取所有键的集合遍历键的集合,获取到每一个键根据键找值
B:案例演示Map集合的遍历之键找值
HashMap<String, String> hashMap = new HashMap<>();hashMap.put("文章", "马伊琍");hashMap.put("王宝强", "蓉儿");hashMap.put("贾乃亮", "李小璐");hashMap.put("陈羽凡", "白百合");hashMap.put("陈思成", "佟丽亚");hashMap.put("大郎", "金莲");//String val = hashMap.get("文章");//System.out.println(val);//遍历Map集合的方式// 方式1:采用 键找值//获取所有键的集合Set<String> keySet = hashMap.keySet();System.out.println(keySet);//[贾乃亮, 文章, 王宝强, 陈思成, 大郎, 陈羽凡]for (String key : keySet) {String value = hashMap.get(key);System.out.println(key + "=====" + value);}System.out.println("=========================");

18.06_集合框架(Map集合的遍历之键值对对象找键和值)(掌握)

A:键值对对象找键和值思路:获取所有键值对对象的集合遍历键值对对象的集合,获取到每一个键值对对象根据键值对对象找键和值
B:案例演示Map集合的遍历之键值对对象找键和值
//方式2:把所有的键值对,对象 Node,对象获取出来。Set<Map.Entry<String, String>> entries = hashMap.entrySet();System.out.println(entries);//[贾乃亮=李小璐, 文章=马伊琍, 王宝强=蓉儿, 陈思成=佟丽亚, 大郎=金莲, 陈羽凡=白百合]for (Map.Entry<String, String> entry : entries) {//System.out.println(entry);String key = entry.getKey();String value = entry.getValue();System.out.println(key + "===" + value);}System.out.println("===============================");
//方式3:hashMap.forEach(new BiConsumer<String, String>() {@Overridepublic void accept(String key, String value) {System.out.println(key + "====" + value);}});

18.07_集合框架(Map集合遍历的两种方式比较图解)(理解)

A:画图演示:  Map集合遍历的两种方式比较

18.08_集合框架(HashMap集合键是Stirng值是String的案例)(掌握)

​ HashMap 允许插入null键 null值
​ A:案例演示: HashMap集合键是Stirng值是String的案例

18.09_集合框架(HashMap集合键是String值是Student的案例)(掌握)

A:案例演示:  HashMap集合键是String值是Student的案例

18.10_集合框架(HashMap集合键是Student值是String的案例)(掌握)

​ 键唯一 注意重写hashCode方法 和 equals 方法
​ A:案例演示: HashMap集合键是Student值是String的案例

18.11_集合框架(LinkedHashMap的概述和使用)(了解)

A:LinkedHashMap的概述:  Map 接口的哈希表和链接列表实现,具有可预知的迭代顺序
B:LinkedHashMap的特点: 底层的数据结构是链表和哈希表 元素有序 并且唯一元素的有序性由链表数据结构保证 唯一性由 哈希表数据结构保证Map集合的数据结构只和键有关C:案例演示: LinkedHashMap的特点
public class MyTest2 {public static void main(String[] args) {LinkedHashSet<String> strings = new LinkedHashSet<>();strings.add("abc");/*  HashSet( int initialCapacity, float loadFactor, boolean dummy){map = new LinkedHashMap<>(initialCapacity, loadFactor);}*///LinkedHashMap 键的数据结构是 链表和哈希表,链表保证了键有序,哈希表保证了键唯一LinkedHashMap<String, String> stringStringLinkedHashMap = new LinkedHashMap<>();stringStringLinkedHashMap.put("s001", "张三");stringStringLinkedHashMap.put("s001", "张三2");stringStringLinkedHashMap.put("s004", "张三3");stringStringLinkedHashMap.put("s005", "张三4");stringStringLinkedHashMap.put("s006", "张三6");stringStringLinkedHashMap.put("s007", "张三8");stringStringLinkedHashMap.put("s008", "张三");//获取所有键的集合//法一Set<String> keySet = stringStringLinkedHashMap.keySet();for (String s : keySet) {System.out.println(s + "===" + stringStringLinkedHashMap.get(s));}System.out.println("========================");//法二Set<Map.Entry<String, String>> entries = stringStringLinkedHashMap.entrySet();for (Map.Entry<String, String> entry : entries) {String key = entry.getKey();String value = entry.getValue();System.out.println(key + "===" + value);}System.out.println("==========================");//法三stringStringLinkedHashMap.forEach(new BiConsumer<String, String>() {@Overridepublic void accept(String key, String value) {System.out.println(key + "==" + value);}});//获取所有值的集合Collection<String> values = stringStringLinkedHashMap.values();System.out.println(values);}
}

18.12_集合框架(TreeMap集合键是String值是String的案例)(掌握)

​ TreeMap 键不允许插入null

A: TreeMap: 键的数据结构是红黑树,可保证键的排序和唯一性  排序分为自然排序和比较器排序 线程是不安全的效率比较高
B:案例演示: TreeMap集合键是Integer值是String的案例
public class MyTest implements Comparable {public static void main(String[] args) {TreeSet<Integer> treeSet = new TreeSet<>();treeSet.add(10);/*  public TreeSet() {this(new TreeMap<E, Object>());}
*///自然排序:要求键实现 Comparable 接口  重写 compareTo(Object o) 这个方法,根据此方法返回值的正负0,来决定元素的放置顺序TreeMap<Integer, String> treeMap = new TreeMap<>();treeMap.put(10, "abcc");treeMap.put(103, "abcc");treeMap.put(170, "abcc");treeMap.put(180, "abcc");treeMap.put(10, "abcc");treeMap.put(106, "abcc");treeMap.put(1220, "abcc");System.out.println(treeMap);}@Overridepublic int compareTo(Object o) {return 0;}
}

18.13_集合框架(TreeMap集合键是Student值是String的案例)(掌握)

A:案例演示:  TreeMap集合键是Student值是String的案例按照年龄大小进行排序 注意键要实现Comparable 接口
public class MyTest2 {public static void main(String[] args) {//双列集合的数据结构,之跟键有关,TreeMap<Student, String> treeMap = new TreeMap<>();treeMap.put(new Student("张三", 23), "s001");treeMap.put(new Student("张三", 23), "s001");treeMap.put(new Student("王老虎", 25), "s001");treeMap.put(new Student("李四", 24), "s002");treeMap.put(new Student("王五", 25), "s003");for (Map.Entry<Student, String> entry : treeMap.entrySet()) {Student key = entry.getKey();String value = entry.getValue();System.out.println(key + "====" + value);}}
}
```java
public class Student implements Comparable<Student> {private String name;private int age;public Student() {}public Student(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}@Overridepublic int compareTo(Student o) {return 0;}
}

18.14_集合框架(统计字符串中每个字符出现的次数)(理解)

A:案例演示:  需求:统计字符串中每个字符出现的次数"aababcabcdabcde",获取字符串中每一个字母出现的次数要求结果:a(5)b(4)c(3)d(2)e(1)

18.15_集合框架(集合嵌套之HashMap嵌套HashMap)(理解)

A:案例演示集合嵌套之HashMap嵌套HashMap

​ 基础班
​ 张三 20
​ 李四 22
​ 就业班
​ 王五 21
​ 赵六 23

public class MyTest {public static void main(String[] args) {//三种遍历map的方法/***                    基础班张三       20李四        22就业班王五     21赵六        23*** */HashMap<String, Integer> jcMap = new HashMap<>();jcMap.put("张三", 20);jcMap.put("李四", 22);HashMap<String, Integer> jyMap = new HashMap<>();jyMap.put("王五", 21);jyMap.put("赵六", 23);HashMap<String, HashMap<String, Integer>> maxMap = new HashMap<>();maxMap.put("基础班", jcMap);maxMap.put("就业班", jyMap);//遍历Map集合/**                   基础班张三        20李四        22就业班王五     21赵六        23*/Set<String> keySet = maxMap.keySet();for (String key : keySet) {System.out.println(key);HashMap<String, Integer> minMap = maxMap.get(key);Set<String> keySet1 = minMap.keySet();for (String s : keySet1) {System.out.println("\t" + s + "    " + minMap.get(s));}//System.out.println();}System.out.println("=======================================");//经典方法for (Map.Entry<String, HashMap<String, Integer>> entry : maxMap.entrySet()) {System.out.println(entry.getKey());for (Map.Entry<String, Integer> en : entry.getValue().entrySet()) {System.out.println("\t" + en.getKey() + "     " + en.getValue());}System.out.println();}System.out.println("===================================");maxMap.forEach(new BiConsumer<String, HashMap<String, Integer>>() {@Overridepublic void accept(String key, HashMap<String, Integer> minMap) {System.out.println(key);minMap.forEach(new BiConsumer<String, Integer>() {@Overridepublic void accept(String s, Integer integer) {System.out.println("\t" + s + "     " + integer);}});}});}
}

18.16_集合框架(集合嵌套之HashMap嵌套ArrayList)(理解)

A:案例演示集合嵌套之HashMap嵌套ArrayList假设HashMap集合的元素是ArrayList。有3个。每一个ArrayList集合的值是字符串。三国演义吕布周瑜笑傲江湖令狐冲林平之神雕侠侣郭靖杨过
public class MyTest {public static void main(String[] args) {/***三国演义吕布周瑜笑傲江湖令狐冲林平之神雕侠侣郭靖杨过*** */ArrayList<String> sgList = new ArrayList<>();sgList.add("吕布");sgList.add("周瑜");ArrayList<String> xaList = new ArrayList<>();xaList.add("令狐冲");xaList.add("林平之");ArrayList<String> sdList = new ArrayList<>();sdList.add("郭靖");sdList.add("杨过");LinkedHashMap<String, ArrayList<String>> maxMap = new LinkedHashMap<>();maxMap.put("三国演义", sgList);maxMap.put("笑傲江湖", xaList);maxMap.put("神雕侠侣", sdList);for (String key : maxMap.keySet()) {System.out.println(key);ArrayList<String> value = maxMap.get(key);for (String s : value) {System.out.println("\t" + s);}}}
}

18.17_集合框架(集合嵌套之ArrayList嵌套HashMap)(理解)

A:案例演示集合嵌套之ArrayList嵌套HashMap假设ArrayList集合的元素是HashMap。有3个。每一个HashMap集合的键和值都是字符串。周瑜---小乔吕布---貂蝉郭靖---黄蓉杨过---小龙女令狐冲---任盈盈林平之---岳灵珊
public class MyTest {public static void main(String[] args) {/*  周瑜-- - 小乔吕布-- - 貂蝉郭靖-- - 黄蓉杨过-- - 小龙女令狐冲-- - 任盈盈林平之-- - 岳灵珊List 嵌套 Map*/HashMap<String, String> sgMap = new HashMap<>();sgMap.put("周瑜", "小乔");sgMap.put("吕布", "貂蝉");HashMap<String, String> sdMap = new HashMap<>();sdMap.put("郭靖", "黄蓉");sdMap.put("杨过", "小龙女");HashMap<String, String> xaMap = new HashMap<>();xaMap.put("令狐冲", "任盈盈");xaMap.put("林平之", "岳灵珊");ArrayList<HashMap<String, String>> maxList = new ArrayList<>();maxList.add(sgMap);maxList.add(sdMap);maxList.add(xaMap);for (HashMap<String, String> hashMap : maxList) {for (Map.Entry<String, String> en : hashMap.entrySet()) {String key = en.getKey();String value = en.getValue();System.out.println(key + "-----" + value);}System.out.println();}}
}

18.18_集合框架(HashMap和Hashtable的区别)(掌握)

A:面试题HashMap和Hashtable的区别:   查看API可以知道HashMap: 线程不安全,效率高.允许null值和null键Hashtable: 线程安全 , 效率低.不允许null值和null键
B:案例演示  HashMap和Hashtable的区别
public class MyTest {public static void main(String[] args) {// HashMap 并允许使用 null 值和 null 键 线程不安全,效率高//  Hashtable 不允许null  值和null 键 线程安全,效率低// Hashtable<String, String> hashMap = new Hashtable<>();//第一次存储键时,返回中时null// hashMap.put("abc", null);//Hashtable}
}

18.19_集合框架(Collections工具类的概述和常见方法讲解)(掌握)

A:Collections类概述:    针对集合操作 的工具类
B:Collections成员方法public static <T> void sort(List<T> list):                 排序,默认按照自然顺序public static <T> int binarySearch(List<?> list,T key):      二分查找public static <T> T max(Collection<?> coll):                获取最大值public static void reverse(List<?> list):                    反转public static void shuffle(List<?> list):                       随机置换
C:案例演示: Collections工具类的常见方法讲解
public class MyTest {public static void main(String[] args) {ArrayList<Integer> list = new ArrayList<>();list.add(100);list.add(108);list.add(600);list.add(700);list.add(108);list.add(110);/*  list.sort(new Comparator<Integer>() {@Overridepublic int compare(Integer a, Integer b) {return b-a;}});*/Collections.sort(list, new Comparator<Integer>() {@Overridepublic int compare(Integer a, Integer b) {return a - b;}});System.out.println(list);//二分查找int index = Collections.binarySearch(list, 100);System.out.println(index);//反转集合中的元素Collections.reverse(list);System.out.println(list);//获取集合中的最值Integer max = Collections.max(list);Integer min = Collections.min(list);System.out.println(max);System.out.println(min);//随机打乱集合中元素的顺序Collections.shuffle(list);System.out.println(list);Collections.shuffle(list);System.out.println(list);Collections.shuffle(list);System.out.println(list);}
}

18.20_集合框架(模拟斗地主洗牌和发牌)(理解)

A:案例演示:  模拟斗地主洗牌和发牌,牌没有排序
public class MyTest {public static void main(String[] args) {/*  A:案例演示:模拟斗地主洗牌和发牌看牌,牌没有排序一副牌 54 张牌*///1.创建一个牌盒ArrayList<String> pokerBox = new ArrayList<>();//2.生成54张牌,装到牌盒里面//花色 和 序号String[] colors = {"♣", "♥", "♦", "♠"};String[] nums = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};//组合花色和序号for (String color : colors) {for (String num : nums) {pokerBox.add(color.concat(num));}}//收到添加大小王pokerBox.add("☀");pokerBox.add("☂");//System.out.println(pokerBox);//斗地主3个人  留一副底牌ArrayList<String> 星仔 = new ArrayList<>();ArrayList<String> 刀仔 = new ArrayList<>();ArrayList<String> 高进 = new ArrayList<>();ArrayList<String> 底牌 = new ArrayList<>();//洗牌Collections.shuffle(pokerBox);Collections.shuffle(pokerBox);Collections.shuffle(pokerBox);// System.out.println(pokerBox);//斗地主3个人  留一副底牌//发牌:一人一张轮流张发// 一次数好发给你// 星仔 = (ArrayList<String>) pokerBox.subList(0, 17);//发牌:一人一张轮流发//星仔:0 3 6 9 12    取余  0//刀仔: 1 4 7 10 13   取余  1//高进: 2 5 8 11 14   取余  2for (int i = 0; i < pokerBox.size(); i++) {if (i >= pokerBox.size() - 3) {底牌.add(pokerBox.get(i));} else if (i % 3 == 0) {星仔.add(pokerBox.get(i));} else if (i % 3 == 1) {刀仔.add(pokerBox.get(i));} else {高进.add(pokerBox.get(i));}}//看牌lookPoker("星仔", 星仔);lookPoker("刀仔", 刀仔);lookPoker("高进", 高进);lookPoker("底牌", 底牌);}private static void lookPoker(String name, ArrayList<String> list) {System.out.println(name);for (String p : list) {System.out.print(p + " ");}System.out.println();}
}

18.21_集合框架(模拟斗地主洗牌和发牌并对牌进行排序的原理图解)(理解)

A:画图演示:  画图说明排序原理

18.22_集合框架(模拟斗地主洗牌和发牌并对牌进行排序的代码实现)(理解)

A:案例演示:  模拟斗地主洗牌和发牌并对牌进行排序的代码实现
public class 斗地主排序版 {public static void main(String[] args) {//创建牌盒HashMap<Integer, String> hm = new HashMap<>();//创建索引集合ArrayList<Integer> indexs = new ArrayList<>();//花色 和 序号String[] colors = {"♣", "♥", "♦", "♠"};String[] nums = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};int index = 0;for (String num : nums) {for (String color : colors) {hm.put(index, num.concat(color));indexs.add(index);index++;}}hm.put(index, "☀");indexs.add(index);index++;hm.put(index, "☹");indexs.add(index);//System.out.println(hm);//System.out.println(indexs);//洗牌Collections.shuffle(indexs);//发牌TreeSet<Integer> 星仔 = new TreeSet<Integer>();TreeSet<Integer> 刀仔 = new TreeSet<Integer>();TreeSet<Integer> 高进 = new TreeSet<Integer>();TreeSet<Integer> 底牌 = new TreeSet<Integer>();for (int i = 0; i < indexs.size(); i++) {if (i >= indexs.size() - 3) {底牌.add(indexs.get(i));} else if (i % 3 == 0) {星仔.add(indexs.get(i));} else if (i % 3 == 1) {刀仔.add(indexs.get(i));} else {高进.add(indexs.get(i));}}//看牌,键找值lookPoker("星仔", 星仔, hm);lookPoker("刀仔", 刀仔, hm);lookPoker("高进", 高进, hm);lookPoker("底牌", 底牌, hm);}private static void lookPoker(String name, TreeSet<Integer> set, HashMap<Integer, String> hm) {System.out.println(name);for (Integer key : set) {System.out.print(hm.get(key) + " ");}System.out.println();}
}

18.23_day18总结

JavaSE Map集合 HashMap和Hashtable的区别 Collections(集合工具类) 集合练习 模拟斗地主(洗牌,发牌,看牌)相关推荐

  1. 18.集合框架(Map集合,HashMap和Hashtable的区别,Collections(集合工具类),集合练习,模拟斗地主(洗牌,发牌,看牌))

    1.Map集合概述和特点 1.需求:    根据学号获取学生姓名 2.Map接口概述     查看API可以知道:     将键映射到值的对象     一个映射不能包含重复的键     每个键最多只能 ...

  2. Day18JavaSE——Map集合Collections工具类集合案例练习

    Day18JavaSE--Map集合&Collections工具类&集合案例练习 文章目录 Day18JavaSE--Map集合&Collections工具类&集合案例 ...

  3. java中Map集合、模拟斗地主洗牌发牌、JDK9对集合添加的优化

    1.1 Map集合概述 Map集合概述 Map==>映射(一个对应一个) Map是一个接口,只要实现了该接口的类都是双列集合. 双列集合每次存储元素时都需要存储两个元素,一个元素称为键,一个元素 ...

  4. Java——集合(HashMap与Hashtable的区别)

    * HashMap和Hashtable的区别* 共同点:* 底层都是哈希算法,都是双列集合* 区别:* 1,HashMap是线程不安全的,效率高* Hashtable是线程安全的,效率低 * 2,Ha ...

  5. HashMap和Hashtable的区别--List,Set,Map等接口是否都继承自Map接口--Collection和Collections的区别...

    面试题: 1.HashMap和Hashtable的区别?HashMap:线程不安全,效率高,键和值都允许null值Hashtable:线程安全,效率低,键和值都不允许null值ArrayList代替V ...

  6. Java集合——HashMap、HashTable以及ConCurrentHashMap异同比较

    转发:https://www.cnblogs.com/zx-bob-123/archive/2017/12/26/8118074.html 0. 前言 HashMap和HashTable的区别一种比较 ...

  7. JAVA面试题:HashMap和Hashtable的区别

    HashMap和Hashtable的区别 1.共同点:都是双列集合,底层都是哈希算法 2.区别: * 1.HashMap是线程不安全的,效率高,JDK1.2版本 * Hashtable是线程安全的,效 ...

  8. 高薪程序员面试题精讲系列36之说说HashMap与HashTable的区别有哪些?

    一. 面试题及剖析 1. 今日面试题 HashMap与HashTable的区别有哪些? hash一致性算法了解吗?原理是什么?底层怎么实现的? ....... 2. 题目剖析 今天这道题目,考察的还是 ...

  9. JAVA 映射HashMap和HashTable的区别和实用

    JAVA 映射HashMap和HashTable的区别和实用 /*  * @author Mr liu  *   * 基本格式:HashMap<key,vaule>  * 面试题  * H ...

  10. hashmap的特性?HashMap底层源码,数据结构?Hashmap和hashtable ConcurrentHashMap区别?

    1.hashmap的特性? 允许空键和空值(但空键只有一个,且放在第一位) 元素是无序的,而且顺序会不定时改变 key 用 Set 存放,所以想做到 key 不允许重复,key 对应的类需要重写 ha ...

最新文章

  1. js前台页面显示中文,后台存对应的value值实现
  2. python变量/分支/循环/数组/列表/元组/序列
  3. Maven项目中使用JUnit进行单元测试
  4. 2019-03-18-算法-进化(实现strStr())
  5. 国家开放大学2021春1257混凝土结构设计原理题目
  6. python时间格式转换为美式日期_如何将日期时间格式的排列转换为python中的打印?...
  7. 苹果cmsV10资源站模板
  8. 观察者模式及其应用场景
  9. python的qrcode模块计算矩阵二维码像素尺寸大小
  10. 安装RabbitMQ出现Plugin configuration unchanged.问题
  11. JVAV SE学习总结(01)
  12. Docker--10张图带你深入理解Docker容器和镜像
  13. 在CentOS 7配置IPv6 DNS Server
  14. 如何把pdf转换成excel
  15. 2015给自己充电加薪——免费领取极客学院VIP会员
  16. Xen、OpenVZ、KVM、Hyper-V、VMWare虚拟化技术介绍
  17. matlab极性电容叫什么,什么是无极电容和有极电容,它们在应用上有什么区别? , 无极性电容和有极性电容各自常用在什么电路上?...
  18. 谷歌宣布:上帝的密码防线逐渐崩溃!人工智能有可能是人类文明史的终结!
  19. 把矩形的四个顶点按照一定的顺序排好(左上、右上、右下、左下,符合人的视角).
  20. 神经网络预测值几乎一样,神经网络预测出现负值

热门文章

  1. 特殊字符ascii码
  2. C#简单实现office转pdf、pdf转图片
  3. Python实现远程控制桌面功能(不使用微信等任何接口),并在不同局域网下控制(已更新)
  4. 由pushViewController说起可能出线的各种死法
  5. 利用python实现PSM
  6. 贪吃蛇“大作战”(二)
  7. excel小写转大写公式_不要眨眼!中英文、大小写转换,一秒就搞定!
  8. magic2410支持大容量sdhc卡解决办法
  9. ALS算法的基本思想
  10. nginx+uWSGI+django+virtualenv+supervisor发布web服务器流程