Map<?, Optional> to Map [duplicate]
This question already has answers here: Best way to convert Map<Object, Optional<Object>> to Map<Object, Object>? (2 answers) Closed 15 days ago. I have a Map with Optional values. I want to filter it to remove empty values. Map<K, Optional<T>> input; Map<K, T> result = input. // here is some code I’m looking for .collect(Collector.toMap(???)); What […]
“Interim condition check” in Java Stream
I am searching for “interim condition check” in the Java stream chain.
search values by priority in stream
I have a simple list of results, and I need to return only one value depending on content, for example:
java8 stream map().collect() java.lang.Object cannot be converted to java.util.List
import com.google.common.collect.Lists; import lombok.Data; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class Test { public static void main(String[] args) { TaskNode taskNode = new TaskNode(); ArrayList<TaskNode> taskNodeList = Lists.newArrayList(taskNode); List<String> nodeStateList2 = taskNodeList.stream() .map(taskNode1 -> getString(taskNode1.getConfig(), “”)) .collect(Collectors.toList()); } public static <K> String getString(final Map<? super K, ?> map, final K […]
Java iterate over list of objects and create map based on condition
I have a list of Employee objects, which has name and list of PhoneNumbers objects. Phone Number class has number and active fields. I need to create a map of Employee::Name and Employee::PhoneNumber such that phone number is active.
Java streams, upsort first N matching elements, then all other elements
I’m curious if there’s an elegant (stream-only) way to return a partially sorted stream where the first n matching elements of some predicate are at the front, and the rest of the elements follow.
Java 8 compare list of integer and list of Object
I have input of Ids
Sort Map using java streams
How to sort a map with the key first and sort the values as well.
java lambda Transform a map<K, List> to map<K, List>
I need to transform a map:
Stream map returns null instead of stream
There is a list of elements of the Event class.