/home/wpollock1/public_html/Java/DeduplicateList.java

// Demo of using a LinkedHashSet to deduplicate a List while preserving
// the list order.  (Note sure if this is efficient, however it is clever.)
//
// Written 11/2015 by Wayne Pollock, Tampa Florida USA

import java.util.*;

class DeduplicateList
{
   public static void main ( String [] args )
   {
      List<String> names = new ArrayList<>();
      names.add( new String( "Wayne" ) );
      names.add( new String( "Jane" ) );
      names.add( new String( "Anna" ) );
      names.add( new String( "Hiro" ) );
      names.add( new String( "Kim" ) );
      names.add( new String( "Wayne" ) );
      names.add( new String( "Anna" ) );
      names.add( new String( "Sam" ) );
      names.add( new String( "Wayne" ) );

      // De-duplicate the list
      System.out.println( "Before deduplication: " +
         Arrays.deepToString( names.toArray() ) );

      Set<String> dedupNames = new LinkedHashSet<>( names );
      names.clear();
      names.addAll( dedupNames );

      System.out.println( "After deduplication:  " +
         Arrays.deepToString( names.toArray() ) );
   }
}