home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
HashSet5.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
1KB
|
37 lines
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
/**
* Counting, finding, removing with duplicates allowed.
*
* @see com.objectspace.jgl.HashSet
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class HashSet5
{
public static void main( String[] args )
{
HashSet set = new HashSet( true ); // allow duplicates
set.add( "cat" );
set.add( "ape" );
set.add( "dog" );
set.add( "bat" );
set.add( "dog" );
System.out.println( set );
System.out.println( "set.count( dog ) = " + set.count( "dog" ) );
HashSetIterator i = set.find( "dog" );
if ( i.equals( set.end() ) ) // A simpler way: if ( i.atEnd() ) ...
System.out.println( "Could not find dog." );
else
System.out.println( "Found " + i.get() );
System.out.println( "set.remove( dog ) = " + set.remove( "dog" ) );
HashSetIterator j = set.find( "dog" );
if ( j.atEnd() ) // A simpler way: if ( j.equals( set.end() ) ) ...
System.out.println( "Could not find dog." );
else
System.out.println( "Found " + j.get() );
}
}