Java guides
Every published Java guide, newest first, with practical examples you can copy into your own project.
3,965 guides across 14 topics
Topics
Popular Java guides
Most readLatest Java guides
Page 29 of 109Java Optional orElseThrow: Usage and Examples
Learn how to use Optional.orElseThrow() to unwrap values, throw custom exceptions, and avoid the pitfalls of get(), orElse(), and orElseGet().
Java Optional orElseGet: Lazy Default Values Explained
Java Optional.orElseGet supplies a default value lazily. See how it differs from orElse, when to use it, and how to avoid unnecessary work and side effects.
Java Optional orElse: Usage and Pitfalls
Learn how to use Java Optional orElse correctly, including its eager evaluation, differences from orElseGet, and common pitfalls.
Java Optional.get(): Usage, Risks, and Safer Alternatives
Learn how Java Optional.get() works, why it throws NoSuchElementException, and safer alternatives like orElse, orElseGet, orElseThrow, and map.
Java Optional ifPresentOrElse Explained
Learn how to use Optional.ifPresentOrElse to handle present and absent values in a single functional expression, with syntax, examples, and edge cases.
Java Optional ifPresent: Usage and Pitfalls
Learn how to use Java Optional.ifPresent() correctly, manage side effects, avoid common mistakes, and decide when it is a better choice than traditional null checks.
java optional isempty: Using Optional.isEmpty() in Java
java optional isempty: Learn how to use Optional.isEmpty() in Java 11+ to check for absent values, compare it with isPresent(), and avoid common pitfalls.
Java Optional isPresent: Usage and Pitfalls
Understand when Java's Optional.isPresent() is appropriate, why pairing it with get() is an anti-pattern, and how ifPresent(), orElse(), and map() make code safer and more concise.
Java Optional Empty: How to Check and Handle
java optional empty: Learn how to detect and handle empty Optional instances in Java, including isPresent(), orElse, and orElseGet patterns.
Using Optional.ofNullable to Handle Null in Java
How Optional.ofNullable works, how it differs from Optional.of, and practical examples for handling nullable values in Java.