Java examples for java.util:Set Operation
Clone a set.
//package com.java2s; import java.util.Collection; import java.util.LinkedHashSet; import java.util.Set; public class Main { /**//from ww w . j a v a 2 s . co m * Clone a set. * <p> * It simply copies the source set to a new {@link #LinkedHashSet}. * * @param src - Source set * @return the LinkedHashSet with copied values. */ public static <T, M extends Set<? extends T>> LinkedHashSet<T> cloneSet( M src) { return copySet(src, new LinkedHashSet<T>()); } /** * Copy a set to another one. * * @param src - Source set * @param dst - Destination set * @return the destination set. */ public static <T, M extends Set<? extends T>, N extends Set<? super T>> N copySet( M src, N dst) { return copyCollection(src, dst); } /** * Copy a collection to another one. * * @param src - Source collection * @param dst - Destination collection * @return the destination collection. */ public static <T, M extends Collection<? extends T>, N extends Collection<? super T>> N copyCollection( M src, N dst) { synchronized (src) { synchronized (dst) { dst.clear(); for (T element : src) dst.add(element); return dst; } } } }