import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
public class ForEachTest {
public static void main(String[] args) {
Collection<Suit> suits=Arrays.asList(Suit.values());
Collection<Rank> ranks=Arrays.asList(Rank.values());
List<Card> deck=new ArrayList<Card>();
for(Iterator<Suit> i=suits.iterator();i.hasNext();){
for(Iterator<Rank> j=ranks.iterator();j.hasNext();){
System.out.println(i.next().toString()+ j.next().toString());
}
}
for(Suit i:suits){
for(Rank j:ranks){
System.out.println(i.toString()+ j.toString());
}
}
}
}
enum Suit{A,B,C,D,E}
enum Rank{H,I,J,K,L}
class Card{
private Suit suit;
private Rank rank;
public Card() {
// TODO Auto-generated constructor stub
}
public Card(Suit suit, Rank rank) {
super();
this.suit = suit;
this.rank = rank;
}
public Suit getSuit() {
return suit;
}
public void setSuit(Suit suit) {
this.suit = suit;
}
public Rank getRank() {
return rank;
}
public void setRank(Rank rank) {
this.rank = rank;
}
}
java for-each
最新推荐文章于 2017-01-05 17:38:12 发布