Java Set to ArrayList cast(Set set)

Here you can find the source of cast(Set set)

Description

Casts a Set to a Set with a different element type.

License

Open Source License

Parameter

Parameter Description
set Set

Return

Set of desired type

Declaration

@SuppressWarnings({ "unchecked" })
public static <T> Set<T> cast(Set<?> set) 

Method Source Code

//package com.java2s;
/*//from ww w . java  2 s .c  o m
 // This software is subject to the terms of the Eclipse Public License v1.0
 // Agreement, available at the following URL:
 // http://www.eclipse.org/legal/epl-v10.html.
 // You must accept the terms of that agreement to use this software.
 //
 // Copyright (C) 2001-2005 Julian Hyde
 // Copyright (C) 2005-2012 Pentaho and others
 // All Rights Reserved.
 */

import java.util.*;

public class Main {
    /**
     * Casts a Set to a Set with a different element type.
     *
     * @param set Set
     * @return Set of desired type
     */
    @SuppressWarnings({ "unchecked" })
    public static <T> Set<T> cast(Set<?> set) {
        return (Set<T>) set;
    }

    /**
     * Casts a List to a List with a different element type.
     *
     * @param list List
     * @return List of desired type
     */
    @SuppressWarnings({ "unchecked" })
    public static <T> List<T> cast(List<?> list) {
        return (List<T>) list;
    }
}

Related

  1. cast(Set p)
  2. cast(Set set)
  3. setToArrayList(Set set)
  4. setToArrayList(Set set)