Java List to Set toSet(List list)

Here you can find the source of toSet(List list)

Description

to Set

License

Open Source License

Declaration

public static <T> Set<T> toSet(List<T> list) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    public static <T> Set<T> toSet(List<T> list) {
        Set<T> set = new HashSet<T>();
        for (T t : list) {
            if (!set.contains(t)) {
                set.add(t);// w  ww  .  j av a 2s  .  c o m
            }
        }
        return set;
    }
}

Related

  1. listToSet(final BsonArray array)
  2. listToSet(List list)
  3. toSet(List sources)
  4. toSet(List list, Comparator comparator)
  5. toSet(List list)
  6. toSet(Optional> list)

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