需求:用户在选择多个时间区间之后,如选择的时间区间连续或者有重叠,需要对所选的时间区间进行合并
这其实是一个区间合并问题,为了简化操作,将拿到的集合进行排序后再合并
废话不多说,源码如下:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @ClassName DateU
* @Description TODO
* @Author kk_star
* @Date 2021/4/9 14:59
*/
public class DateU {
public static void main(String[] args) {
List<DateEntity> list = new ArrayList<>();
DateEntity de1 = new DateEntity("2021-01-10","2021-02-15");
DateEntity de2 = new DateEntity("2021-01-01","2021-01-06");
DateEntity de3 = new DateEntity("2021-03-01","2021-03-15");
DateEntity de4 = new DateEntity("2021-01-07","2021-01-09");
DateEntity de5 = new DateEntity("2021-02-16","2