fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. public enum Strings {
  12. STRING_ONE("ONE"),
  13. STRING_TWO("TWO")
  14. ;
  15. private static final Map<String,Strings> byName = new HashMap<String,Strings>();
  16. private final String text;
  17.  
  18. private Strings(final String text) {
  19. this.text = text;
  20. }
  21. static {
  22. for (Strings s : Strings.values()) {
  23. byName.put(s.toString(), s);
  24. }
  25. }
  26. @Override
  27. public String toString() {
  28. return text;
  29. }
  30. public static Strings forName(String name) {
  31. return byName.get(name);
  32. }
  33. }
  34. public static void main (String[] args) throws java.lang.Exception
  35. {
  36. System.out.println(Strings.forName("TWO"));
  37. }
  38. }
Success #stdin #stdout 0.07s 381248KB
stdin
Standard input is empty
stdout
TWO