[阅读: 497] 2005-10-29 12:29:37
import java.util.*;
public class pass {
private String test[] = { "a", "b", "c",
"d", "a", "b", "c", "e", "f",
"g", "c", "d" };
// create and output ArrayList
public pass()
{
ArrayList list;
list = new ArrayList( Arrays.asList( test ) );
System.out.println( "ArrayList: " + list );
printNonDuplicates( list );
}
public void printNonDuplicates( Collection collection )
{
// create a HashSet and obtain its iterator
HashSet set = new HashSet( collection );
Iterator iterator = set.iterator();
System.out.println( "\nNonduplicates are: " );
while ( iterator.hasNext() )
System.out.print( iterator.next() + " " );
System.out.println();
}
// execute application
public static void main( String args[] )
{
new pass();
}
}