Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

String manipulation

  Asked By: Ludwig    Date: Jul 18    Category: Java    Views: 821
  

I have the following problem:

I have these 3 strings stored in an string array

array[0]: Juice Milk Yogurt
array[1]: Milk Juice Yogurt
array[2]: Yogurt Juice Milk

Since these strings have the same elements I need to remove the
redundant ones. One method is to break them into single element and
then compare them, but this is not efficient. I was wodering if
there is a better method.

Actually, I am implementing Aprori algo. of data mining and if
possible can anybody let me know which data structures to use for
such a problem.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Felicia Hill     Answered On: Jul 18

Look into one of the implementations of java.util.Set(
AbstractSet, HashSet, LinkedHashSet or TreeSet).
All you have to do is call add() passing in your
Strings
and it will "remove" duplicates for you.

After that if you need to use it as an array just call
the toArray() function of Set which returns an
Object[] .

 
Didn't find what you were looking for? Find more on String manipulation Or get search suggestion and latest updates.




Tagged: