3 ways to flatten a list of lists. Is there a reason to prefer one of them?
问题 Assume we have a list as follows. CoreResult has a field of type List<Double> . final List<CoreResult> list = new LinkedList<>(SOME_DATA); The objective is to flatten the list after extracting that specific field from each CoreResult object. Here are 3 possible options. Is any one of them preferable to the others? Option 1 : extract a field via map() and flatten inside collector final List<Double> A = list.stream().map(CoreResult::getField) .collect(ArrayList::new, ArrayList::addAll,