我有'一個字符串例如=「該網站擁有的Java開發者年鑑等。複製所有的例子,並且這些例子直接粘貼到你的應用程序」後,令牌如何合併數組列表元素?
,做一些我想要的字符串例子,我有數組列表等:
ArrayList <token > arl = " "this site holds ", "holds all the examples ", "the examples from The Java Developers", " Copy and paste ")
「這個網站持有」,我知道位置開始和結束字符串測試:星= 1個端= 3 「包含所有的實施例中」,我知道位置STAT = 3端= 6,我知道position stat = 5 end = 10, 「複製並粘貼」我知道position stat = 14 end = 「The Java Developers的例子」 17,
我們可以看到,arl中的某些元素重疊:「本網站擁有」,「擁有所有示例」,「來自The Java Developers的示例」。
這裏的問題是,我該如何合併overlaping元素recived的ArrayList像
ArrayList的結果=「」這個網站擁有的Java開發人員的所有實例」,‘’複製和粘貼‘’;
這裏我的代碼:但只合並拳頭elecment如果檢查元素overloaping
public ArrayList<TextChunks> finalTextChunks(ArrayList<TextChunks> textchunkswithkeyword) {
ArrayList<TextChunks > result = (ArrayList<TextChunks>) textchunkswithkeyword.clone();
//System.out.print(result.size());
int j;
for(int i=0;i< result.size() ;i++) {
int index = i;
if(i+1>=result.size()){
break;
}
j=i+1;
if(result.get(i).checkOverlapingTwoTextchunks(result.get(j))== true) {
TextChunks temp = new TextChunks();
temp = handleOverlaping(textchunkswithkeyword.get(i),textchunkswithkeyword.get(j),resultSearchEngine);
result.set(i, temp);
result.remove(j);
i = index;
continue;
}
}
return result;
}
}
感謝avadce
我不知道我明白你在問什麼。你能澄清你的問題嗎?也許通過使用一個看起來不像問題一部分的示例字符串? – jasonmp85 2010-06-02 04:25:55
Sory因爲我的英文很弱,我一直在編輯我的問題,希望你能理解! – tiendv 2010-06-02 04:44:56