import java.util.*;class test1
{
public static void main(String[] args) 
{
HashMap m=new HashMap();
 m.put("one",new Integer(1));
 m.put("two",new Integer(2));
 m.put("three",new Integer(3));
String str="one";
int c=((Integer) m.get(str)).intValue();
switch (c){
  case 1: System.out.println("one"); break;
  case 2: System.out.println("two"); break;
  case 3: System.out.println("three"); break;
}
}
}这样可以实现你的要求,不过好像有点得不偿失哦.

解决方案 »

  1.   

    谢谢,我只是想扩展一下自己的思路,不想总是if else的写程序,所以不在乎什么效率之类的,不过当然效率越高越好啦。
      

  2.   

    class text{
    private static  final String a="3";
    }
      

  3.   

    不好意思上面点错了,如果你单单是实现上面的东西,那么应该是if最高效了.下面是我乱写的
    class test{
      private static final int ONE=1;
      private static final int TWO=2;
      private static final int THREE=3;
      int c=this.ONE;
      switch (c){
      case ONE: System.out.println("one"); break;
      case TWO: System.out.println("two"); break;
      case THREE: System.out.println("three"); break;
    }}
      

  4.   

    还是if(){} else if(){}最经典
      

  5.   

    强烈建议用if...else...,这个最高效也最经典,不用更改!!!