collapse duplicate elements in a List - Java java.util

Java examples for java.util:List Duplicate Element

Description

collapse duplicate elements in a List

Demo Code


//package com.java2s;

import java.util.HashSet;
import java.util.List;

import java.util.Set;

public class Main {
    public static void main(String[] argv) {
        List list = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(asSet(list));
    }//from w  w  w  .  ja v a2 s .  co m

    /**
     * can be used to collapse duplicate elements
     * @param list any list of type T
     */
    public static <T> Set<T> asSet(List<T> list) {
        return new HashSet<T>(list);
    }
}

Related Tutorials