– Start
When processing a collection, if there is a null element, it will result in a null pointer exception.
package shangbo.functional.demo17;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
public class App {
public static void main(String[] args) {
List<Integer> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(null);
numbers.add(2);
// filter null
Integer max = numbers.stream().filter(Objects::nonNull).max(Comparator.comparingInt(n -> n)).orElse(null);
System.out.println(max);
}
}
– See more:Java functional programming
– Description: Reprint, please indicate the source
– Last Updated on 2019-06-02
– Written by ShangBo on 2019-06-02
– End
Why can't 80% of the code farmers can't do architects? >>> Use isnull (), nVL (), ifnull () and coalesce () function replacement null value existMySQLThis is written in this: Retu...
2019 Unicorn Enterprises heavily recruiting engineers Python standard >>> The author in the development process, these errors often come across the following usage: 1, a usage error: if (name...
Original link: Java solves if(!=null) the infamous air-judgment processing (Optional) 😝😏 Without further ado, let's take a look at the following code: We can see that in order to obtain a name, mult...
First, the source of the problem (1) It is primarily that when the database is queried, it will return to the empty object, then directly use it directly, it may happen to disaster. eg, Second, refer ...
When we use it, we have to deal with NULL in JSON Just like this I need a empty, but the field must continue to exist result: { "c": 2333, "d": null} It meets expectations. Java re...
We must deal with character stitching during the development process. If the stitching characters are empty, NULL will appear, so what should we do. Let's use the Java8 attribute to deal with it. It c...
Look Arrys.equals () source code when the first line is to determine whether the two parameters ==, suddenly very curious, if both sides are null == No. feasibility of such an approach feasible, then ...
Const char *pha=NULL By default, pha is a null pointer. If you copy it to another pointer and then use delete to release it, it will cause memory leak and even system crash, so it is best to deal with...
Problem Description When the server returns json data, the following data will often appear "somevalue":null The data parsed by the JsonKit third-party library becomes somevalue = "<...