package demo_map; import java.util.*; public class Doudizhu_map { public static void main(String[] args) { List<String> list1=List.of("color joker","black joker"); List<String> list01=List.of("♣","♠","♥","♦"); List<String> list02=List.of("2","A","K","Q","J","10","9","8","7","6","5","4","3"); HashMap<Integer,String> h1=new HashMap<>(); int count=0; h1.put(count++,"color joker"); h1.put(count++,"black joker"); for (String numbers:list02) { for (String color:list01) { String card=color+numbers; h1.put(count++,card); } } Set<Integer> set=h1.keySet(); List<Integer> numList=new ArrayList<Integer>(); numList.addAll(set); System.out.println(numList.toString()); Collections.shuffle(numList); //zhuangpai ArrayList<Integer> gamer1=new ArrayList<>(); ArrayList<Integer> gamer2=new ArrayList<>(); ArrayList<Integer> gamer3=new ArrayList<>(); ArrayList<Integer> rest=new ArrayList<>(); for(int key=0;key<numList.size();key++){ if(key>50){ rest.add(numList.get(key)); }else if(key%3==0){ gamer1.add(numList.get(key)); }else if(key%3==1){ gamer2.add(numList.get(key)); }else if (key%3==2){ gamer3.add(numList.get(key)); } } Collections.sort(rest); Collections.sort(gamer1); System.out.println(gamer1); Collections.sort(gamer2); Collections.sort(gamer3); LinkedHashMap<Integer,String> restm=new LinkedHashMap<>(); for (int i = 0; i <rest.size() ; i++) { restm.put(rest.get(i),h1.get(rest.get(i))); } LinkedHashMap<Integer,String> gamer1m=new LinkedHashMap<>(); for (int i = 0; i <gamer1.size(); i++) { gamer1m.put(gamer1.get(i),h1.get(gamer1.get(i))); } LinkedHashMap<Integer,String> gamer2m=new LinkedHashMap<>(); for (int i = 0; i <gamer2.size() ; i++) { gamer2m.put(gamer2.get(i),h1.get(gamer2.get(i))); } LinkedHashMap<Integer,String> gamer3m=new LinkedHashMap<>(); for (int i = 0; i <gamer3.size() ; i++) { gamer3m.put(gamer3.get(i),h1.get(gamer3.get(i))); } System.out.println(restm.toString()); System.out.println(gamer1m.toString()); System.out.println(gamer2m.toString()); System.out.println(gamer3m.toString()); //排序 } }