Java List to Set toSet(Optional> list)

Here you can find the source of toSet(Optional> list)

Description

Returns a new Set populated by all elements in the given list of strings Returns an empty set if the given Optional is empty, or if the list contained in the Optional is empty

License

Open Source License

Declaration

public static Set<String> toSet(Optional<List<String>> list) 

Method Source Code

//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);
    }
}

Related

  1. listToSet(List list)
  2. toSet(List sources)
  3. toSet(List list, Comparator comparator)
  4. toSet(List list)
  5. toSet(List list)

  6. HOME | Copyright © www.java2s.com 2016