java.lang.Enum.valueOf()方法实例

来源:互联网 发布:手机淘宝搜索不到店铺 编辑:程序博客网 时间:2024/06/05 18:59
import java.lang.*;// enum showing Mobile pricesenum Mobile {   Samsung(400), Nokia(250),Motorola(325);   int price;   Mobile(int p) {      price = p;   }   int showPrice() {      return price;   } }public class EnumDemo {   public static void main(String args[]) {     System.out.println("CellPhone List:");     for(Mobile m : Mobile.values()) {         System.out.println(m + " costs " + m.showPrice() + " dollars");     }     Mobile ret;     ret = Mobile.valueOf("Samsung");      System.out.println("Selected : " + ret);                                 }} `这里写代码片`
0 0
原创粉丝点击