package All.D13.Enum_;
public enum PeopleEnum {
People_1,People_2,People_3,People_4
}
package All.D13.Enum_;
public class ShowPeopleEnum {
public static void main(String[] args) {
PeopleEnum p[] = PeopleEnum.values();
for (int i = 0; i < p.length; i++) {
System.out.println("枚举常量有:"+p[i]);
}
}
}
枚举常量有:People_1
枚举常量有:People_2
枚举常量有:People_3
枚举常量有:People_4
在该方法中,values()方法可以将枚举类型成员以数组的形式返回
package All.D13.Enum_;
public enum Constants {
Constants_1, Constants_2, Constants_3
}
package All.D13.Enum_;
public class Demon02 {
public static void main(String[] args) {
Constants enumArray[]=Constants.values();
for (int i = 0; i < enumArray.length; i++) {
System.out.println("枚举数组常量有:"+enumArray[i]);
}
}
}
枚举数组常量有:Constants_1
枚举数组常量有:Constants_2
枚举数组常量有:Constants_3
网友评论