2012-02-06 85 views
0

找出java中2個句子之間的所有獨特詞並保存它們的有效方法是什麼?應該使用什麼數據結構來存儲單詞?在java中找到2個句子之間的區別詞

+1

你的意思是「2句之間的獨特詞語」究竟是什麼意思?另外,如果這是作業,請標記爲這樣。 – NPE 2012-02-06 14:31:28

+0

獨特的含義在2句話中的所有不同的單詞。 – user1080383 2012-02-06 15:33:26

回答

0

將一個句子中的所有單詞放在一個集合中,然後通過第二個句子的單詞。如果單詞存在於一個集合中,請將其從集合中取出,否則將其放入集合中。

1

從HashSet的第一句子存儲的話,然後遍歷在第二句ORDS,看看它在HashSet中已存在

0

實現這一目標的一種簡單方法是:

//I use regular expression to remove punctuation marks 
//II use split to convert the sentences into collections of "words" 
//III create a variable that is an implementation of java.util.set (to store unique words) 
//III iterate over the collections 
// add words from each sentence to the set variable (that way the word will only be stored once) 

希望這有助於