扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

java怎么查看文字列长度

扬州沐宇科技
2023-12-16 11:55:54
Java

在Java中,可以使用String类的length()方法来查看字符串的长度。这个方法返回字符串中字符的数量。下面是一个示例:

String text = "Hello World";
int length = text.length();
System.out.println("Length of the string: " + length);

输出结果将是:

Length of the string: 11

这里,我们使用length()方法获取字符串text的长度,并将结果打印出来。

扫码添加客服微信