public ArrayList<Interval> merge(ArrayList<Interval> intervals) {
		ArrayList<Interval> result = new ArrayList<Interval>();

		if (intervals == null|| intervals.size()==0){
			return result;
		}

		Collections.sort(intervals, IntervalComp);
		Interval interval=intervals.get(0);
		int start = interval.start;
		int end = interval.end;
		for (int i=1;i<intervals.size();i++) {
			interval=intervals.get(i);
			if (interval.start <= end && start <= interval.end) {
				if (interval.start < start) {
					start = interval.start;
				}
				if (interval.end > end) {
					end = interval.end;
				}
			} else {
				result.add(new Interval(start, end));
				start = interval.start;
				end = interval.end;
			}
		}
		result.add(new Interval(start, end));

		return result;
	}