Java length() 方法

Java 教程 · 2019-02-08 22:57:32

length() 方法用于返回字符串的长度。

长度等于字符串中 16 位 Unicode 代码单元的数量。

语法

public int length()

参数

返回值

返回字符串长度。

实例

public class Test {
    public static void main(String args[]) {
        String Str1 = new String("www.codercto.com");
        String Str2 = new String("codercto" );

        System.out.print("字符串 Str1 长度 :");
        System.out.println(Str1.length());
        System.out.print("字符串 Str2 长度 :");
        System.out.println(Str2.length());
    }
}

以上程序执行结果为:

字符串 Str1 长度 :14
字符串 Str2 长度 :6

点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

Web 2.0 Architectures

Web 2.0 Architectures

Duane Nickull、Dion Hinchcliffe、James Governor / O'Reilly / 2009 / USD 34.99

The "Web 2.0" phenomena has become more pervasive than ever before. It is impacting the very fabric of our society and presents opportunities for those with knowledge. The individuals who understand t......一起来看看 《Web 2.0 Architectures》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具