– Java processing null

– 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

Intelligent Recommendation

Database null value and NULL processing

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...

Java String Processing Starter - judging process null or empty values

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...

Java solves if(!=null) infamous air-judgment processing (Optional)

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...

How to make a more elegant processing null value in Java / Web

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 ...

More Recommendation

Python JSON empty value processing java null compatibility

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...

Java 8 processing character stitching has NULL problem

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...

java null == null is established

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 ...

Null pointer processing

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...

Null processing method in Json

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 = "<...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top