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