我想验证日历日期不在java中的日历数组列表中,我这样做了,但它对我不起作用:
List<Calendar> listFeriers = new ArrayList<Calendar>();
startCal = Calendar.getInstance();
startCal.setTime(beginningDate);
endCal = Calendar.getInstance();
endCal.setTime(endDate);
do {
if (!listFeriers.contains(startCal)) {
// Traitement
}
} while (startCal.before(endCal));
最佳答案
List<Calendar> listFeriers = new ArrayList<Calendar>();
我希望你在某个地方填充 listFeriers。
您可以仅将时间以毫秒为单位 (getTimeInMillis) 存储在列表中,而不是创建太多的 Calendar 对象。您可以使用 set 来避免重复的时间条目。
Set<Long> listFeriers = new HashSet<Long>();
if(listFeriers.contains(startCal.getTimeInMillis())){
// A match..
}
关于java - 查找 Calendar 的数组列表中是否存在 Date 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18496101/