Here you can find the source of getYearMonth(String year)
public static List<String> getYearMonth(String year)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; public class Main { private static SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy"); public static List<String> getYearMonth(String year) { if (null == year || "".equals(year.trim())) { year = yearFormat.format(new Date()); }// w ww . j av a 2 s. co m List<String> yearMonth = new ArrayList<String>(); int currentYear = Integer.parseInt(year); int lastYear = Integer.parseInt(year) - 1; for (int j = currentYear; j >= lastYear; j--) { for (int i = 12; i >= 1; i--) { yearMonth.add(j + "-" + String.format("%02d", i)); } } return yearMonth; } }