Skip to content

Instantly share code, notes, and snippets.

@rscarvalho
Created March 10, 2015 19:28
Show Gist options
  • Select an option

  • Save rscarvalho/5789ff105c5ffc4aee8d to your computer and use it in GitHub Desktop.

Select an option

Save rscarvalho/5789ff105c5ffc4aee8d to your computer and use it in GitHub Desktop.
public MyEnum getEnumObject() {
final List<String> enumStrings = new ArrayList<>();
enumStrings.add(null);
enumStrings.add("A");
enumStrings.add("C");
enumStrings.add("B");
enumStrings.add("D");
Optional<MyEnum> e = enumStrings.stream()
.filter(s -> s != null)
.map(MyEnum::valueOf)
.findFirst();
return e.orElseThrow(IllegalStateException::new);
}
public enum MyEnum {
A, B, C, D, E
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment