2013-02-09 78 views
2

如何將array的句子拆分爲array of array的詞? 如果我可以使用split()分割句子..但它只用於單個數組。 但我需要做的多陣列..java將句子拆分成詞

如:

sentences[0]="one sentence" 
sentences[1]=" one sen...." 

我需要拆分這樣的... ...

word[0][0]="one word" //first row first word 
word[0][1]="second word" 
word[0][2]="third word" 
word[1][0]="..."//second row first word** 

任何一個能幫助我。

+0

'分裂()'是String'的'方法,它......你的數組。 – 2013-02-09 05:58:22

+0

請看[for statement](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html)! – 2013-02-09 06:12:14

回答

1

嘗試這樣的事情..

for(i=0;i<someLength;i++){ 
word[i] = sentence[i].split("yourDelimiter"); 
} 
+0

它將顯示爲空。 – user2010228 2013-02-09 13:05:19

+0

如何將一維[]的句子拆分爲單詞的二維[] [] ... – user2010228 2013-02-09 13:08:15

1
String[] sentences = ... 
String[][] words = new String[sentences.length][]; 

for(int i = 0; i < sentences.length; i++) 
{ 
    words[i] = sentences[i].split("\\s+"); 
} 
+0

嗨朋友...它會顯示這[[Ljava.lang.String; @ 1507fb2 ...但不是打印正確的單詞。 – user2010228 2013-02-09 13:04:45

+0

@ user2010228你打印結果如何? – 2013-02-09 14:03:05

+0

@ user2010228請參閱http://stackoverflow.com/a/14717835/597657 – 2013-02-09 15:52:41