How to merge arraylist element ?
Posted
by tiendv
on Stack Overflow
See other posts from Stack Overflow
or by tiendv
Published on 2010-06-02T04:06:34Z
Indexed on
2010/06/02
4:13 UTC
Read the original article
Hit count: 186
java
I have a string example = " Can somebody provide an algorithm sample code in your reply ",
after token and do some i want on string example i have arraylist like :
ArrayList <token > arl = " "Can somebody provide ", "code in your ", "somebody provide an algorith", " in your reply" )
"Can somebody provide ", i know position start and end in string test : star = 1 end = 3 " code in your ", i know position stat = 7 end = 10, "somebody provide an algorith", i know position stat = 7 end = 10, "in your reply" i know position stat = 11 end = 14,
we can see,some element in arl overlaping :"Can somebody provide "," code in your ","somebody provide an algorith".
The problem here is how can i merge overlaping element to recived arraylist like
ArrayList result ="" Can somebody provide an algorithm sample code","" in your reply"";
Here my code : but it only merge fist elecment if check is 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;
}
Thanks in avadce
© Stack Overflow or respective owner