Java DateFormatSymbols setMonths() Example
DateFormatSymbols class setMonths() method example. This example shows you how to use setMonths() method.
Syntax is : public void setMonths(String[] newMonths)
This meethod sets month strings to the specified string array. For example: "January", "February", etc.
Here is the code.
/**
* @(#) SetMonthsDateFormatSymbols.java
* A class representing use of method setMonths() of DateFormatSymbols
class in java.text Package.
* @Version 16-May-2008
* @author Rose India Team
*/
import java.text.*;
class SetMonthsDateFormatSymbols {
public static void main(String[] args) {
// Create new DateFormatSymbols object with getInstance() method.
DateFormatSymbols dFormatSymbols = DateFormatSymbols.getInstance();
// getMonths() method call.
String[] months = dFormatSymbols.getMonths();
System.out.println("Months of date format symbol : ");
for (int i = 0; i < months.length; i++) {
System.out.println(months[i]);
}
// setMonths method call.
String[] str = {"Mahendra", "Girish"};
dFormatSymbols.setMonths(str);
months = dFormatSymbols.getMonths();
System.out.println("Months after setMonths() method : ");
for (int i = 0; i < months.length; i++) {
System.out.println(months[i]);
}
}
} |
Output of the program.
Months of date format symbol :
January
February
March
April
May
June
July
August
September
October
November
December
Months after setMonths() method :
Mahendra
Girish |
|