How to get list of year in java between two value?

Aqmal :

I try to get list of year in java. For example i want to print year from 2018 until the current year only. Anyone can help me on this ?

arunken :

You can do the following :

List<Integer> years = new ArrayList<Integer>();
int endYear = Calendar.getInstance().get(Calendar.YEAR);
for(int year = 2018;year <= endYear; year++){
    System.out.println(year);// if you just want to print the years.
    years.add(year);// if you want to store the years in an array list.
}

Here, Calendar.getInstance().get(Calendar.YEAR) can be used to get the current year. As you already know the starting year(for eg 2018), we can use this to create a loop for obtaining the required result.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=193894&siteId=1