How to merge arraylist element?
<p>I have  `a string example = "this site holds all the examples from The Java Developers Almanac and more. Copy and paste these examples directly into your applications"</p>

<p>after token and do some i want on string example  i have arraylist like :</p>

<pre><code>ArrayList &lt;token &gt; arl = " "this site holds ", "holds all the examples ", "the examples from The Java Developers", " Copy and paste " )
</code></pre>

<p>"this site holds ", i know position start and end in string test : star = 1 end = 3
" holds all the examples ", i know position  stat = 3 end = 6, 
 "the examples from The Java Developers", i know position  stat = 5 end =10,
 "Copy and paste" i know position  stat = 14 end = 17,</p>

<p>we can see,some element in arl overlaping :"this site holds ","holds all the examples ","the examples from The Java Developers".</p>

<p>The problem here is how can i merge overlaping element to recived arraylist like </p>

<p>ArrayList  result ="" this site holds all the examples from The Java Developers","" Copy and paste"";</p>

<p>Here my code : but it only merge fist elecment if check is element overloaping</p>

<pre><code>public ArrayList&lt;TextChunks&gt; finalTextChunks(ArrayList&lt;TextChunks&gt; textchunkswithkeyword) {
        ArrayList&lt;TextChunks &gt; result = (ArrayList&lt;TextChunks&gt;) textchunkswithkeyword.clone();
            //System.out.print(result.size());
            int j;
            for(int i=0;i&lt; result.size() ;i++) {
                int index = i;
                if(i+1&gt;=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;  
    }
}
</code></pre>

<p>Thanks in avadce</p>
