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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Optional<Animal> anAnimalThatMeows =
  13. EnumSet
  14. .allOf(Animal.class)
  15. .stream()
  16. .filter(( Animal animal ) -> animal.getSound().equals("meow"))
  17. .findAny() ;
  18. System.out.println( anAnimalThatMeows );
  19. }
  20. }
  21.  
  22. enum Animal {
  23. DOG("bark"),
  24. CAT("meow");
  25.  
  26. public final String sound;
  27.  
  28. Animal(String sound) {
  29. this.sound = sound;
  30. }
  31.  
  32. public String getSound() {
  33. return sound;
  34. }
  35. }
  36.  
Success #stdin #stdout 0.15s 54264KB
stdin
Standard input is empty
stdout
Optional[CAT]