<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Optional on Devops Monk</title><link>https://devops-monk.com/tags/optional/</link><description>Recent content in Optional on Devops Monk</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 04 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://devops-monk.com/tags/optional/index.xml" rel="self" type="application/rss+xml"/><item><title>Java 8 Best Practices and Patterns for Production Code</title><link>https://devops-monk.com/tutorials/java8/java8-best-practices/</link><pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate><guid>https://devops-monk.com/tutorials/java8/java8-best-practices/</guid><description>Streams Best Practices Do: Use streams for transformations and aggregations // Good: filter → transform → collect List&amp;lt;String&amp;gt; premiumNames = customers.stream() .filter(Customer::isPremium) .map(Customer::getName) .sorted() .collect(Collectors.toList()); // Good: aggregation Map&amp;lt;String, Long&amp;gt; countByCity = customers.stream() .collect(Collectors.groupingBy(Customer::getCity, Collectors.counting())); Don&amp;rsquo;t: Use streams for simple indexed iteration // Bad: stream for something a loop does more clearly IntStream.range(0, list.size()) .forEach(i -&amp;gt; System.out.println(i + &amp;#34;: &amp;#34; + list.get(i))); // Good: traditional loop wins here for (int i = 0; i &amp;lt; list.</description></item><item><title>Optional: Eliminating NullPointerException the Right Way</title><link>https://devops-monk.com/tutorials/java8/optional/</link><pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate><guid>https://devops-monk.com/tutorials/java8/optional/</guid><description>The Problem Optional Solves NullPointerException is the most common runtime exception in Java. The root cause is that null is used for two different things simultaneously:
&amp;ldquo;This field has no value&amp;rdquo; (intentional absence) &amp;ldquo;This reference was never set&amp;rdquo; (programming error) Callers can&amp;rsquo;t tell which meaning applies without reading the documentation or source code. And nothing in the type system forces them to check.
// Java 7: what does null mean here?</description></item><item><title>Stream &amp; Optional API Enhancements (Java 9–11)</title><link>https://devops-monk.com/tutorials/java11/stream-optional-enhancements/</link><pubDate>Mon, 04 May 2026 00:00:00 +0000</pubDate><guid>https://devops-monk.com/tutorials/java11/stream-optional-enhancements/</guid><description>Stream API — New Methods (Java 9) Java 9 added four new instance methods to Stream&amp;lt;T&amp;gt;. All are terminal-ish or intermediate operations that make common patterns expressible without workarounds.
takeWhile(Predicate) Returns elements from the beginning of the stream as long as the predicate holds, then stops. The first element that fails the predicate (and all subsequent elements) are discarded.
Stream.of(1, 2, 3, 4, 5, 1, 2) .takeWhile(n -&amp;gt; n &amp;lt; 4) .</description></item></channel></rss>