企业网站开发语言,上海网站开发设计,酒店网站建设的基本内容,网站检测工具文章目录 集合嵌套List嵌套ListList嵌套MapMap嵌套Map Collections类方法排序 sort 乱序 shuffle 斗地主案例需求思路代码 日志框架介绍优势体系结构Logback概述快速入门配置详解 集合嵌套 List嵌套List
public static void main(String[] args){//一个年级有许多班级#xf… 文章目录 集合嵌套List嵌套ListList嵌套MapMap嵌套Map Collections类方法排序 sort 乱序 shuffle 斗地主案例需求思路代码 日志框架介绍优势体系结构Logback概述快速入门配置详解 集合嵌套 List嵌套List
public static void main(String[] args){//一个年级有许多班级每个班级有许多学生学生有姓名//定义班级ListString classes1List new ArrayList();classes1List.add(zhangsan);classes1List.add(lisi);classes1List.add(wangwu);ListString classes2List new ArrayList();classes2List.add(zhangsan2);classes2List.add(lisi2);classes2List.add(wangwu2);ListString classes3List new ArrayList();classes3List.add(zhangsan3);classes3List.add(lisi3);classes3List.add(wangwu3);//定义年级ListListString gradeList new ArrayList();gradeList.add(classes1List);gradeList.add(classes2List);gradeList.add(classes3List);//遍历gradeListfor (ListString classes : gradeList) {for (int i 0; i classes.size(); i) {System.out.println(classes.get(i));}System.out.println(--------------------);}}List嵌套Map
public static void main(String[] args) {//先定义班级MapString,String classes1Map new HashMap();classes1Map.put(001,zhangsan);classes1Map.put(002,lisi);classes1Map.put(003,wangwu);MapString,String classes2Map new HashMap();classes2Map.put(001,zhangsan2);classes2Map.put(002,lisi2);classes2Map.put(003,wangwu2);MapString,String classes3Map new HashMap();classes3Map.put(001,zhangsan3);classes3Map.put(002,lisi3);classes3Map.put(003,wangwu3);//定义年级ListMapString,String gradeList new ArrayList();gradeList.add(classes1Map);gradeList.add(classes2Map);gradeList.add(classes3Map);//遍历for (MapString, String classes : gradeList) {for (Map.EntryString, String entry : classes.entrySet()) {String id entry.getKey();String name entry.getValue();System.out.println(id -- name);}System.out.println(------------------);}
}Map嵌套Map public static void main(String[] args) {//先定义班级MapString,String classes1Map new HashMap();classes1Map.put(001,zhangsan);classes1Map.put(002,lisi);classes1Map.put(003,wangwu);MapString,String classes2Map new HashMap();classes2Map.put(001,zhangsan2);classes2Map.put(002,lisi2);classes2Map.put(003,wangwu2);MapString,String classes3Map new HashMap();classes3Map.put(001,zhangsan3);classes3Map.put(002,lisi3);classes3Map.put(003,wangwu3);//再定义年级MapString,MapString,String gradeMap new HashMap();gradeMap.put(第一个班级,classes1Map);gradeMap.put(第二个班级,classes2Map);gradeMap.put(第三个班级,classes3Map);//遍历for (String s : gradeMap.keySet()) {System.out.println(--------------);for (Map.EntryString, String entry : gradeMap.get(s).entrySet()) {String id entry.getKey();String name entry.getValue();System.out.println(s : id -- name);}}}Collections类 方法 排序 sort 乱序 shuffle 斗地主案例 需求 思路
准备牌 完成数字和纸牌的映射使用Map集合利用list集合记录牌的编号 洗牌利用Collections.shuffle方法对其洗牌发牌将牌的编号对3取余剩下3张作为底牌 利用TreeSet集合保存三个人的拍编号 看牌通过TreeSet集合中牌的编号利用Map集合查看牌
代码
public static void main(String[] args) {//准备牌MapInteger, String pokerMap new HashMap();ListInteger pokerNum new ArrayList();preparePoker(pokerMap, pokerNum);//洗牌Collections.shuffle(pokerNum);//System.out.println(pokerNum);//发牌TreeSetInteger player1 takePoker(pokerNum,1);TreeSetInteger player2 takePoker(pokerNum,2);TreeSetInteger player3 takePoker(pokerNum,3);TreeSetInteger dp takePoker(pokerNum,0);// System.out.println(player1);
// System.out.println(player2);
// System.out.println(player3);
// System.out.println(dp);//看牌lookPoker(zhangsan, player1, pokerMap);lookPoker(lisi, player2, pokerMap);lookPoker(wangwu, player3, pokerMap);lookPoker(底牌, dp, pokerMap);}//准备牌public static void preparePoker(MapInteger, String pokerMap, ListInteger pokerNum) {String[] colors {♠, ♥, ♣, ♦};String[] numbers {2, A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3};int index 0;pokerMap.put(index, 大王);pokerNum.add(index);index;pokerMap.put(index, 小王);pokerNum.add(index);index;for (int i 0; i numbers.length; i) {for (int j 0; j colors.length; j) {pokerMap.put(index, colors[j] numbers[i]);pokerNum.add(index);index;}}//System.out.println(pokerMap);}//发牌public static TreeSetInteger takePoker(ListInteger pokerNum,Integer id) {TreeSetInteger player1 new TreeSet();TreeSetInteger player2 new TreeSet();TreeSetInteger player3 new TreeSet();TreeSetInteger dp new TreeSet();//底牌for (int i 0; i pokerNum.size(); i) {if (i pokerNum.size() - 4) {dp.add(pokerNum.get(i));} else if (i % 3 0) {player1.add(pokerNum.get(i));} else if (i % 3 1) {player2.add(pokerNum.get(i));} else if (i % 3 2) {player3.add(pokerNum.get(i));}}if (id 0){return dp;} else if (id 1) {return player1;}else if (id 2){return player2;} else if (id 3) {return player3;}return new TreeSet();}//看牌public static void lookPoker(String name, TreeSetInteger player, MapInteger, String pokerMap) {System.out.println(name 的牌是);for (Integer pokerNum : player) {String poker pokerMap.get(pokerNum);System.out.print(poker );}System.out.println();}日志框架 介绍
程序中的日志可以用来记录程序中运行过程中的信息并可以进行永久存储
优势
可以将系统执行的信息选择性的记录到指定的位置(控制台文件数据库中)可以随时以开关的形式控制是否记录日志无需修改源代码
体系结构 Logback 概述 快速入门 配置详解