title: Insert Elements to an ArrayList like intervals java
body: <p>First example: I have ranges</p>
  
  <pre><code>[10, 30] [80, 100] [150, 200]
  </code></pre>
  
  <p>I have to insert for example <code>[90, 120]</code>. After, insertion, the resulting ranges will be:</p>
  
  <pre><code>[10, 30] [80, 120] [150, 200]
  </code></pre>
  
  <p>This happens because the range <code>[100, 120]</code> was not in the original range, so 100 gets increased to 120, but 90 will not be added because is in the range of 80 to 120.</p>
  
  <p>Similarly, if I were to add <code>[50, 90]</code> to the original range, the resulting range would be</p>
  
  <pre><code>[10, 30] [50, 100] [150, 200]
  </code></pre>
  
  <p>This time, the lower bound gets reduced to 50, widening the range on the lower side, but the 90 is ignored because it is already in the range <code>[80, 100]</code>. I am attempting to make a class to represent this problem.</p>
  
  <p>Currently, I take the start numbers into ArrayListStart <code>[10, 80, 150]</code> and the end numbers into ArrayListEnd <code>[30, 100, 200]</code> and I loop through them. I compare if it is smaller of the smallest number etc.</p>
  
  <p>However, I cannot seem to get this method to work. Can anyone help me solve this problem?</p>