title: Intersecting overlapping intervals in Java
body: <p>I have an input set of date ranges that may overlap. Instead of combining these overlapping date ranges, I want to create new date ranges with adjusted dates, e.g.: </p>
  
  <pre><code>|---------------------–|
          |-----| 
              |--------------–|
  </code></pre>
  
  <p>should end up in: </p>
  
  <pre><code>|-------|---|-|--------|----|
  </code></pre>
  
  <p>Is there an efficient way to solve this with Java? </p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>UPDATE:</strong>
  I didn't mention my own approach in my first question, so here it is: I'd simply take the start and the end date of an interval and add it to a sorted set. Afterwards I'd  iterate over the set and create new intervals based on re-ordered dates.</p>