Last active
March 28, 2019 05:37
-
-
Save ariesmcrae/cb76e31f4280096a0f3d86ed9cedc64f to your computer and use it in GitHub Desktop.
Optional nullable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.ariesmcrae.combination.service; | |
| import java.util.Arrays; | |
| import java.util.Collections; | |
| import java.util.List; | |
| import java.util.Optional; | |
| import java.util.stream.Collectors; | |
| public class Main { | |
| public static void main(String... args) { | |
| List<String> adjustmentPlansWrapper = null; | |
| List<String> adjustmentPlans = Optional.ofNullable(adjustmentPlansWrapper) | |
| .orElse(Collections.emptyList()) | |
| .stream() | |
| .parallel() | |
| .collect(Collectors.toList()); | |
| System.out.println(adjustmentPlans); | |
| adjustmentPlansWrapper = Arrays.asList("a", "b"); | |
| adjustmentPlans = Optional.ofNullable(adjustmentPlansWrapper) | |
| .orElse(Collections.emptyList()) | |
| .stream() | |
| .parallel() | |
| .collect(Collectors.toList()); | |
| System.out.println(adjustmentPlans); | |
| } | |
| } | |
| //Result: | |
| //[] | |
| //[a, b] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment