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

查看所有标签

The Haskell School of Expression

The Haskell School of Expression

Paul Hudak / Cambridge University Press / 2000-01 / USD 95.00

Functional programming is a style of programming that emphasizes the use of functions (in contrast to object-oriented programming, which emphasizes the use of objects). It has become popular in recen......一起来看看 《The Haskell School of Expression》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

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

HEX HSV 互换工具