首页 > 其他 > 详细

[源码] 定义String s="abcd", 求长度

时间:2018-12-01 10:25:20      阅读:204      评论:0      收藏:0      [点我收藏+]

一般会答: s.length()

看源码是如何实现的:

    /**
     * Returns the length of this string.
     * The length is equal to the number of <a href="Character.html#unicode">Unicode
     * code units</a> in the string.
     *
     * @return  the length of the sequence of characters represented by this
     *          object.
     */
    public int length() {
        return value.length;
    }

value就是一个字符数组, 即s.length()其实是调用char[]的length属性

    /** The value is used for character storage. */
    private final char value[];

[源码] 定义String s="abcd", 求长度

原文:https://www.cnblogs.com/52liming/p/10048154.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!