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]);
}
System.out.println("============");
for (PeopleEnum tmp:p
) {
System.out.println("foreach方法输出的枚举成员类型有:"+tmp);
}
}
}
枚举常量有:People_1
枚举常量有:People_2
枚举常量有:People_3
枚举常量有:People_4
============
foreach方法输出的枚举成员类型有:People_1
foreach方法输出的枚举成员类型有:People_2
foreach方法输出的枚举成员类型有:People_3
foreach方法输出的枚举成员类型有:People_4
使用foreach增强语句也可以进行循环遍历
网友评论