Here you can find the source of toSet(List
public static <T> Set<T> toSet(List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static <T> Set<T> toSet(List<T> list) { return Collections.unmodifiableSet(new HashSet<>(list)); }//w w w.j av a 2s . c o m }