Pin It

How to display or get list of months names in Java ?.

Program to implement how to display or get list of months names in Java

package com.hubberspot.lists;

import java.text.DateFormatSymbols;

public class MonthsListDemo {

 public static void main(String[] args) {

  // Create a DateFormatSymbols instance 
  DateFormatSymbols dfs = new DateFormatSymbols();

  // DateFormatSymbols instance has a method by name
  // getMonths() which returns back an array of 
  // months name 
  String[] arrayOfMonthsNames = dfs.getMonths();

  // loop over each month name and printing on the 
  // console
  for( String monthName : arrayOfMonthsNames ) { 

   System.out.println(monthName);

  }

  dfs = new DateFormatSymbols();

  // DateFormatSymbols instance has a method by name
  // getShortMonths() which returns back an array of 
  // months name in short forms
  String[] arrayOfShortMonthsNames = dfs.getShortMonths();

  // loop over each month name and printing on the 
  // console
  for( String monthName : arrayOfShortMonthsNames ) { 

   System.out.println(monthName);

  }

 }

}



Output of the program : 

 
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot