I want to extract unique elements from a string.
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.StringTokenizer;
/**
*
* @author Animesh Pandey
*/
public class Main {
/**
* @param args the command line arguments
*/
public static Set getUniqueTokens(String str, String separator) {
StringTokenizer tokenizer = new StringTokenizer(str, separator);
Set tokens = new HashSet();
while (tokenizer.hasMoreTokens()) {
tokens.add(tokenizer.nextToken());
}
return tokens;
}
public static void main(String[] args) {
String s1 = "The Map interface maps unique keys to value means it associate value to unique keys which you use to retrieve value at a later date interface maps unique keys to value means "
+ "associate value to unique keys which you.";
Set unique = getUniqueTokens(s1, " ");
Iterator uniset = unique.iterator();
while (uniset.hasNext()){
Object element = uniset.next();
System.out.println(element);
}
}
}
This is a program for it but what should I do if Ineed to ignore the words like 'it, to, a, an, the, is, are' ????
Please Help!