```
public List<Interval> insert(List<Interval> intervals, Interval newInterval) {
if(newInterval == null) return intervals;
int first = 0;
/*find first overlapping interval*/
while(first < intervals.size() && newInterval.start > intervals.get(first).end)
first++;
/*merge intervals */
while(first < intervals.size() && newInterval.end >= intervals.get(first).start)
{
newInterval = new Interval(Math.min(newInterval.start,intervals.get(first).start),
Math.max(newInterval.end,intervals.get(first).end));
intervals.remove(first);
}
intervals.add(first,newInterval);
return intervals;
}
```