MonthDay 的 toString() 方法
可以使用 Java 中 MonthDay 類中的 toString() 方法獲得 MonthDay 物件的字串值。此方法不要求任何引數,它返回 MonthDay 物件的字串值。
以下是一個演示它的程式 −
示例
import java.time.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md.toString()); } }
輸出
The MonthDay is: --02-22
下面我們來理解一下上面的程式。
使用 toString() 方法獲得 MonthDay 的字串值,然後列印這個值。下面的程式碼片段演示了這一點 −
MonthDay md = MonthDay.parse("--02-22"); System.out.println("The MonthDay is: " + md.toString());
廣告