📌  相关文章
📜  Java中的 WeekFields toString() 方法及示例

📅  最后修改于: 2022-05-13 01:55:20.928000             🧑  作者: Mango

Java中的 WeekFields toString() 方法及示例

WeekFields 类toString()方法用于返回此 WeekFields 对象的字符串表示形式。

句法:

public String toString()

参数:此方法不接受任何内容。

返回值:此方法返回此 WeekFields 的字符串表示形式。

下面的程序说明了 WeekFields.toString() 方法:
方案一:

// 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);
    }
}
输出:
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);
    }
}
输出:
String representation :WeekFields[SUNDAY, 1]

参考:https: Java/time/temporal/WeekFields.html#toString()