62,620
社区成员
发帖
与我相关
我的任务
分享
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author closewubq
*/
public class Test {
public static void main(String[] args) throws InterruptedException {
List<String> list = new ArrayList<String>();
list.add("5月23日");
list.add("5月26日");
list.add("5月1日-5月22日");
list.add("7月4日");
list.add("7月5日");
list.add("6月10日");
list.add("6月1日-6月20日");
list.add("6月21日");
list.add("7月5日-7月25日");
String key = "";
boolean flag = false;
Pattern p = Pattern.compile("月(\\d+)日");
Matcher m = null;
int day = 0;
List<String> list1 = new ArrayList<String>();
for (int i = 0; i < list.size(); i++) {
if (!list.get(i).contains("-")) {
key = list.get(i);
for (int j = 0; j < list.size(); j++) {
if (list.get(j).contains("-")
&& list.get(j).startsWith(key.substring(0, 1))) {
int[] date = new int[2];
int count = 0;
m = p.matcher(list.get(j));
while (m.find())
date[count++] = Integer.parseInt(m.group(1));
m = p.matcher(key);
if (m.find())
day = Integer.parseInt(m.group(1));
if (date[0] <= day && date[1] >= day)
flag = true;
}
}
if (!flag)
list1.add(list.get(i));
flag = false;
} else
list1.add(list.get(i));
}
String[] str = new String[list1.size()];
str = list1.toArray(new String[0]);
Arrays.sort(str);
System.out.println(Arrays.toString(str));
}
}