import java.util.*;
public class Collections_Class {
public static void main(String[] args){
String[] colors={"黑桃","红桃","梅花","方块"};
String[] numbers={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
ArrayList cards = new ArrayList();
int i,j;
for(i=0;i<4;i++){
for(j=0;j<12;j++){
cards.add(colors[i]+numbers[j]);
System.out.print(cards.get(i*12+i+j)+",");
}
cards.add(colors[i]+numbers[j]);
System.out.println(cards.get(i*12+i+j));
}
Collections.sort(cards);//升序
for(i=0;i<4;i++){
for(j=0;j<12;j++){
System.out.print(cards.get(i*12+i+j)+",");
}
System.out.println(cards.get(i*12+i+j));
}
升序的输出结果:
方块10,方块2,方块3,方块4,方块5,方块6,方块7,方块8,方块9,方块A,方块J,方块K,方块Q
梅花10,梅花2,梅花3,梅花4,梅花5,梅花6,梅花7,梅花8,梅花9,梅花A,梅花J,梅花K,梅花Q
红桃10,红桃2,红桃3,红桃4,红桃5,红桃6,红桃7,红桃8,红桃9,红桃A,红桃J,红桃K,红桃Q
黑桃10,黑桃2,黑桃3,黑桃4,黑桃5,黑桃6,黑桃7,黑桃8,黑桃9,黑桃A,黑桃J,黑桃K,黑桃Q
我想知道它是怎么升序的,按什么样的规则来排序??????????????
我想知道它是怎么升序的,按什么样的规则来排序??????????????