Here you can find the source of rangeOf(final Date date, final int beforeDates, final int afterDates)
public static List<Date> rangeOf(final Date date, final int beforeDates, final int afterDates)
//package com.java2s; //License from project: Apache License import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; public class Main { public static final long DATE = TimeUnit.DAYS.toMillis(1); public static List<Date> rangeOf(final Date date, final int beforeDates, final int afterDates) { final Calendar c = Calendar.getInstance(); c.setTime(date);//from w w w .java 2 s.c o m final int size = beforeDates + afterDates + 1; final List<Date> list = Arrays.asList(new Date[size]); list.set(beforeDates, date); for (int i = beforeDates; i > 0;) { c.add(Calendar.DATE, -1); list.set(--i, c.getTime()); } c.add(Calendar.DATE, size); final int j = beforeDates + 1; for (int i = size; i > j;) { c.add(Calendar.DATE, -1); list.set(--i, c.getTime()); } return list; } }