4.74 参考/String length 方法

String length 方法

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

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

语法

public int length()

参数

返回值

返回字符串长度。

实例

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

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

以上程序执行结果为:

字符串 Str1 长度 :16
字符串 Str2 长度 :8
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务