在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的长度,并将结果打印出来。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>