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://www.codercto.com/courses/l/12.html

查看所有标签

Visual Thinking

Visual Thinking

Colin Ware / Morgan Kaufmann / 2008-4-18 / USD 49.95

Increasingly, designers need to present information in ways that aid their audiences thinking process. Fortunately, results from the relatively new science of human visual perception provide valuable ......一起来看看 《Visual Thinking》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器