Here you can find the source of toSet(List
public static <T> Set<T> toSet(List<T> list)
//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; } }