java:枚举
public enum InfoLight {
RED,GREEN,BLUE;
}
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
public class Driver {
public static void main(String[] args) {
//获取系统剩余的内存空间
long begin1 = Runtime.getRuntime().freeMemory();
//获取系统的当前时间
long start01 = System.currentTimeMillis();
for (InfoLight rgb : InfoLight.values()) {
System.out.println(rgb.name());
}
System.out.println("*************************************");
InfoLight infoLight=InfoLight.BLUE;
System.out.println(infoLight);
// enum---->string
System.out.println(infoLight.name());
// 定义时的序号
System.out.println(infoLight.ordinal());
//String--->enum
System.out.println(InfoLight.valueOf("BLUE").name());
System.out.println(InfoLight.valueOf("wanson")); //不存在
System.out.println("\t\t");
//获取系统剩余的内存空间
long end2 = Runtime.getRuntime().freeMemory();
//获取系统的当前时间 单位是毫秒
long finish02 = System.currentTimeMillis();
System.out.println("本程序占用内存:" + (begin1 - end2));
System.out.println("本程序占用时间:" + (finish02 - start01));
}
}
posted on 2019-05-06 13:53 Indian_Mysore 阅读(99) 评论(0) 编辑 收藏 举报