"" .value如何评估java String类中的值?

时间:2018-01-26 15:10:08

标签: java string

以下是从String.class中获取的代码段。 "" .value如何计算java String class中的值?

 private final char value[];
 /**
 * Initializes a newly created {@code String} object so that it represents
 * an empty character sequence.  Note that use of this constructor is
 * unnecessary since Strings are immutable.
 */
public String() {
    this.value = "".value;
}

我想了解String ..中的equals()的默认行为。

public boolean equals(Object anObject) {
    if (this == anObject) {
        return true;
    }
    if (anObject instanceof String) {
        String anotherString = (String)anObject;
        int n = value.length;
        if (n == anotherString.value.length) {
            char v1[] = value;
            char v2[] = anotherString.value;
            int i = 0;
            while (n-- != 0) {
                if (v1[i] != v2[i])
                    return false;
                i++;
            }
            return true;
        }
    }
    return false;

}

所以不清楚n是如何从上面代码中的value.length获取值的。

1 个答案:

答案 0 :(得分:0)

for(let i=1; i<10; i++) $(`#toggle${i}`).click(() => $(`#panel${i}`).slideToggle("fast") )与其他任何人一样""

它是通过调用与此处显示的构造函数不同的构造函数创建的。该构造函数已为String字段分配了一个数组;该值恰好与value相同。

问题中的构造函数只是访问该字符串的字段。它就像:

new char[0]