title: Filtering out integers (indexes) from Arraylist
body: <p>I have an arraylist of different phrases such as, "protein", " protein kinase", "functional", "functional protein", "sox5", "il-6", Now, if I give a sentence as input, "functional protein kinase and il-6 and sox5", it must provide output as, "{functional protein} kinase and {il-6} and {sox5}". Every word in the sentence must be compared with the phrases.</p>
  
  <p>The code that I have done returns me starting and ending indexes of different strings which are compared with the arraylist of different phrases. I need to filter out only the indexes which is largest and without any collisions. 
  For e.g.
  Input:</p>
  
  <p>[0, 7][8, 22][8, 15] [36, 43] [23, 43] [20, 30] </p>
  
  <p>Required output:</p>
  
  <p>[0, 7] [8, 22] [23, 43]</p>
  
  <p>Cases:</p>
  
  <ul>
  <li>Between [8, 22] and [8, 15], [8, 22] is the largest because 22-8 = 14 > 15-8 = 7, so [8,22] must be selected.</li>
  <li>Between [36, 43], [23, 43] and [20, 30], 36 lies in the range [23, 43] and 30 also lies in the range [23, 43] which is collision but among these collisions, [23, 43] is
  largest and must be selected.</li>
  </ul>
  
  <p>What should I do in order to get the required output? (comparing criteria)</p>
  
  <p>I have done,</p>
  
  <pre><code>ArrayList&lt;ArrayList&lt;Integer&gt;&gt; ListOfList = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();
  for(int a = 0; a&lt;ListOfList.size();a++)
          {
              if(a == ListOfList.size()-1) break;
              for(int b = a+1; b&lt;ListOfList.size();b++)
              {
                  if((ListOfList.get(a).get(0) == ListOfList.get(b).get(0)) &amp;&amp; (ListOfList.get(a).get(1) &lt; ListOfList.get(b).get(1)))     
                  {
                      startOffset = ListOfList.get(b).get(0);
                      endOffset =  ListOfList.get(b).get(1);
                  }
                  else
                  {
                      startOffset = ListOfList.get(a).get(0);
                      endOffset =  ListOfList.get(a).get(1);
                  }
              } 
          }
  </code></pre>