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());
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP