public List<Interval> merge(List<Interval> intervals) {
		 List <Interval> mergedList = new ArrayList<Interval>();
		if (intervals == null) return mergedList;
		if (intervals.isEmpty()) return mergedList;
		
       
        for (Interval interval: intervals)
        {
        	 insertInterval(interval);
        }
        
        Object[] startList = mapIntervals.keySet().toArray();
        Arrays.sort(startList);
        Interval interval1 = null, interval2 = null;
        for(Object key : startList)
        {
        	interval1 = mapIntervals.get(key);
        	if (isOverlap(interval1, interval2))
        	{
        		interval2 = mergeIntervals(interval1, interval2);
        	}
        	else
        	{
        		mergedList.add(interval2);
        		interval2 = interval1;
        	}    		
        }
        mergedList.add(interval2);
        
        return mergedList;
    }