Link to home
Start Free TrialLog in
Avatar of shajihase
shajihase

asked on

Removing duplicates from two dimensional string array

I have a two dimensional string array . I want to delete the duplicate items and form a new array with available items. How do I do that.
Avatar of sankars98
sankars98


 Use Hashtable. Put all the String values in it and then get the keys then form the string array again..
Avatar of shajihase

ASKER

Can you show me apiece of code how to do that?

Thanks

=============================================
 String[] strArray = { "Test1" , "Test2" , "Test1" };

 Hashtable table = new HashTable();
 for( int i = 0 ; i < strArray.length ; i++ ){
      table.put( strArray[i].trim() , "" );
}

 Enumeration keys = table.keys();

 String[] newArray = new String[ table.size() ];
 for( int i = 0; keys.hasMoreElements() ; i++ ){
      newArray[i] = ( String ) keys.nextElement();    
 }

============================================
ASKER CERTIFIED SOLUTION
Avatar of sreedhar_gari
sreedhar_gari

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial