Relative Content

Tag Archive for javajava-stream

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 […]

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 […]