Collections: unmodifiableSet(Set s) : Collections « java.util « Java by API






Collections: unmodifiableSet(Set s)

  
/*
22.5
5
354.5676

*/



import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.swing.JPanel;

/**  
 * Demonstrates the use of instance comparisons.
 *
 * @author <a href=mailto:kraythe@arcor.de>Robert Simmons jr. (kraythe)</a>
 * @version $Revision: 1.3 $
 */
public class InstanceOfDemo {
  /** A set of demon objects. */
  public static final Set OBJECT_SET;

  static {
    Set objectSet = new HashSet();
    objectSet.add(new Integer(5));
    objectSet.add(new String("Hardcore Java"));
    objectSet.add(new Float(22.5f));
    objectSet.add(new JPanel());
    objectSet.add(new Character('x'));
    objectSet.add(new ArrayList());
    objectSet.add(new Double(354.5676));
    objectSet.add(null);
    OBJECT_SET = Collections.unmodifiableSet(objectSet);
  }

  /** 
   * Demo method.
   *
   * @param args Command Line arguments.
   */
  public static void main(final String[] args) {
    final Iterator iter = OBJECT_SET.iterator();
    Object obj = null;

    while (iter.hasNext()) {
      obj = iter.next();
      if (obj instanceof Number) {
        System.out.println(obj);
      }
    }
  }
}

/* ########## End of File ########## */

           
         
    
  








Related examples in the same category

1.Collections.EMPTY_LIST
2.Collections.EMPTY_MAP
3.Collections.EMPTY_SET
4.Collections: binarySearch(List list, T key)
5.Collections: comparator()
6.Collections: copy(List dest, List src)
7.Collections: emptyList()
8.Collections: emptyMap()
9.Collections: emptySet()
10.Collections: enumeration(Collection c)
11.Collections: fill(List list, R obj)
12.Collections: list(Enumeration e)
13.Collections: max(Collection < ? extends T > coll)
14.Collections: min(Collection < ? extends T > coll)
15.Collections: nCopies(int n, Object o)
16.Collections: reverse(List list)
17.Collections: reverseOrder()
18.Collections: replaceAll(List list, T oldVal, T newVal)
19.Collections: rotate(List list, int distance)
20.Collections: shuffle(List < ? > list,Random rnd)
21.Collections: singleton(T o)
22.Collections: singletonList(T o)
23.Collections: singletonMap(T key, R value)
24.Collections: sort(List list)
25.Collections: sort(List < T > list, Comparator < ? super T > c)
26.Collections: swap(List list, int i, int j)
27.Collections: synchronizedCollection(Collection c)
28.Collections: synchronizedList(List list)
29.Collections: synchronizedMap(Map m)
30.Collections: synchronizedSet(Set s)
31.Collections: synchronizedSet(SortedSet s)
32.Collections: synchronizedSortedMap(SortedMap m)
33.Collections: unmodifiableCollection(Collection c)
34.Collections: unmodifiableList(List list)
35.Collections: unmodifiableMap(Map m)