The toString() method of WeekFields class is used to return string representation of this WeekFields object.
Syntax:
Java
Java
public String toString()Parameters: This method accepts nothing. Return value: This method returns string representation of this WeekFields. Below programs illustrate the WeekFields.toString() method: Program 1:
// Java program to demonstrate
// WeekFields.toString() method
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
public class GFG {
public static void main(String[] args)
{
// create WeekFields
WeekFields weekFields
= WeekFields.of(DayOfWeek.MONDAY, 1);
// apply toString()
String toString = weekFields.toString();
// print results
System.out.println("String representation :"
+ toString);
}
}
Output:
Program 2:
String representation :WeekFields[MONDAY, 1]
// Java program to demonstrate
// WeekFields.toString() method
import java.time.temporal.WeekFields;
import java.util.Locale;
public class GFG {
public static void main(String[] args)
{
Locale locale = new Locale("EN", "INDIA");
// create WeekFields
WeekFields weekFields = WeekFields.of(locale);
// apply toString()
String toString = weekFields.toString();
// print results
System.out.println("String representation :"
+ toString);
}
}
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#toString()String representation :WeekFields[SUNDAY, 1]