Top "Optional" questions

An immutable type that may contain a value or reference.

Default optional parameter in Swift function

When I set firstThing to default nil this will work, without the default value of nil I get a error …

swift function optional
Java 8 optional: ifPresent return object orElseThrow exception

I'm trying to make something like this: private String getStringIfObjectIsPresent(Optional<Object> object){ object.ifPresent(() ->{ String …

java lambda optional
Check string for nil & empty

Is there a way to check strings for nil and "" in Swift? In Rails, I can use blank() to check. …

swift string optional is-empty
Java 8 - Difference between Optional.flatMap and Optional.map

What's the difference between these two methods: Optional.flatMap() and Optional.map()? An example would be appreciated.

java java-8 optional
Uses for Optional

Having been using Java 8 now for 6+ months or so, I'm pretty happy with the new API changes. One area I'm …

java java-8 optional
How to return when an optional is empty?

I love that optionals are in the Java standard library now. But there is one basic problem I keep running …

java nullable optional
'Optional.get()' without 'isPresent()' check

I have the following search code in Java: return getTableViewController().getMe().getColumns().stream().filter($->Database.equalsColumnName($.getId(), columnId)).…

java java-8 java-stream optional
Regex optional group

I am using this regex: ((?:[a-z][a-z]+))_(\d+)_((?:[a-z][a-z]+)\d+)_(\d{13}) to match strings like this: SH_6208069141055_BC000388_20110412101855 separating …

regex optional regex-group
Why does findFirst() throw a NullPointerException if the first element it finds is null?

Why does this throw a java.lang.NullPointerException? List<String> strings = new ArrayList<>(); strings.add(null); …

java java-8 java-stream optional
Optional orElse Optional in Java

I've been working with the new Optional type in Java 8, and I've come across what seems like a common operation …

java lambda java-8 optional java-9