package com.mindprod.example;
import java.util.Arrays;
import java.util.HashSet;
import static java.lang.System.*;
/**
* example use of java.util.HashSet. Sample code to TEST and demonstrate the use of HashSet.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01 initial version
* @since 2009-01-01
*/
public final class TestHashSet
{
/**
* Sample code to TEST and demonstrate the use of HashSet.
*
* @param args not used
*/
public static void main( String[] args )
{
HashSet<String> regions = new HashSet<>( 149
, 0.75f
);
regions.add( "WA" );
regions.add( "NY" );
regions.add( "RI" );
regions.add( "BC" );
regions.add( "ON" );
boolean isLegit = regions.contains( "NY" );
out.println( isLegit );
out.println( "enumerate all the elements in the regions HashSet, unordered" );
for ( String region : regions )
{
out.println( region );
}
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 )
{
out.println( region );
}
}
}