import java.util.*;
class Demo
{
public static void main(String[] args)
{
String[] color = {"黑桃","红桃","梅花","方块"};
String[] number = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
StackList list = new StackList();
for (int i = 0;i < 4 ;i++ )
{
for (int j = 0;j < 13 ;j++ )
{
list.add(new Poker(color[i],number[j]));
}
}
System.out.println(list.list);
Random random = new Random();
int a = 0;
StackList newList = new StackList();
while (a < 52)
{
Object poker = list.get(random.nextInt(52));
if (!newList.contains(poker))
{
newList.add(poker);
}
a = newList.size();
}
System.out.println("\n\n洗完牌后:" + newList.list);
}
}
class Poker
{
public String toString(){
return color + number;
}
public boolean equals(Object obj){
Poker n = (Poker)obj;
return this.color.equals(n.color) && this.number.equals(n.number);
}
}
class StackList
{
LinkedList list;
public StackList(){
list = new LinkedList();
}
public void add(Object m){
list.offer(m);
}
public Object poll(){
return list.poll();
}
public int size(){
return list.size();
}
public Object get(int index)
{
return list.get(index);
}
public boolean contains(Object o){
return list.contains(o);
}
}