Here you can find the source of toSet(Optional> list)
public static Set<String> toSet(Optional<List<String>> list)
//package com.java2s; //License from project: Open Source License import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.Set; public class Main { /**/*from w w w . java 2 s . com*/ * Returns a new Set populated by all elements in the given list of strings * Returns an empty set if the given {@code Optional} is empty, * or if the list contained in the {@code Optional} is empty */ public static Set<String> toSet(Optional<List<String>> list) { List<String> elements = list.orElse(Collections.emptyList()); return new HashSet<>(elements); } }