Between the two implementations, which one is better?
import org.apache.commons.lang3.stream.Streams;
public static <T> T firstNonNull(final T... values) {
return Streams.of(values).filter(Objects::nonNull).findFirst().orElse(null);
}
or
public static <T> T firstNonNull(final T... values) {
if (values != null) {
for (final T val : values) {
if (val != null) {
return val;
}
}
}
return null;
}
The context is that of a general-purpose utility class intended for use throughout the application. Indeed, performance is one concern.