Skip to content

Instantly share code, notes, and snippets.

@Gabbendorf
Last active May 22, 2019 14:52
Show Gist options
  • Save Gabbendorf/2d34800f4aa0921f6d0c703f191fd20f to your computer and use it in GitHub Desktop.
Save Gabbendorf/2d34800f4aa0921f6d0c703f191fd20f to your computer and use it in GitHub Desktop.
Java Optional: example that throws an IndexOutOfBoundsException
public Member memberById(List<Member> members, int memberId) {
return members.stream()
.filter(member -> member.getId() == memberId)
.collect(Collectors.toList())
.get(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment