import
java.util.EnumSet; →滙入EnumSet
class
apples{
public
static
void
main(String args[]){
for(tuna
people: tuna.values())
System.out.printf("%s\t%s\t%s\n",
people, people.getDesc(),people.getYear());
System.out.println("\n
And now for the range of constants!!!\n");
for
(tuna people:
EnumSet.range(tuna.kelsy,
tuna.candy))
→從哪裡開始和結束
System.out.printf("%s\t%s\t%s\n",
people, people.getDesc(),people.getYear());
}
}
public
enum
tuna {
bucky("nice","22"),
kelsy("cutie","10"),
julia("bigmistake","12"),
nicole("italian",
"13"),
candy("different",
"14"),
erin("iwish",
"16");
private
final
String desc;
private
final
String year;
tuna(String
description, String birthday){
desc=description;
year=birthday;
}
public
String getDesc(){
return
desc;
}
public
String getYear(){
return
year;
}
}
這是運行時的結果:
And
now for the range of constants!!!
kelsy cutie 10
julia bigmistake 12
nicole italian 13
candy different 14
沒有留言:
張貼留言