package com.mindprod.example;
import java.util.Arrays;
import java.util.HashSet;
/**
* example use of java.util.HashSet. Sample code to TEST and demonstrate the use of HashSet. requires JDK 1.5+
* <p/>
* composed with IntelliJ IDEA
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0
*/
public final class TestHashSet
{
/**
* Sample code to TEST and demonstrate the use of HashSet. requires JDK 1.5+
*
* @param args not used
*/
public static void main( String[] args )
{
HashSet<String> regions = new HashSet<String>( 149
, 0.75f
);
regions.add( "WA" );
regions.add( "NY" );
regions.add( "RI" );
regions.add( "BC" );
regions.add( "ON" );
boolean isLegit = regions.contains( "NY" );
System.out.println( isLegit );
System.out.println( "enumerate all the elements in the regions HashSet, unordered" );
for ( String region : regions )
{
System.out.println( region );
}
System.out.println( "enumerate all the elements in the regions HashSet, sorted" );
String[] sortedRegions = regions.toArray( new String[regions.size()] );
Arrays.sort( sortedRegions );
for ( String region : sortedRegions )
{
System.out.println( region );
}
}
}