Online Java Compiler By
JavaTpoint.com
import java.util.*; public class JavaCalendargetDisplayNameExample3 { public static void main(String[] args) { // create calendar and locale Calendar cal1 = Calendar.getInstance(); Locale loc = Locale.getDefault(); // geting all the months using getDisplayName method //and assigning it to a String tree set Map< String, Integer> tset = cal1.getDisplayNames(Calendar.MONTH, Calendar.LONG, loc); NavigableMap< String, Integer> Map = new TreeMap< String, Integer>(tset); // print the results System.out.printf("List of Months are :%n%s%n", Map); } }
Output