Negative string length

Do you have a negative string length? If so, is it the same as null?

+3
source share
6 answers

No; string length is 0 (empty string, represented as "") or higher. And the empty string does not coincide with the null (in Java it is not called a null string ).

To better understand what null means in Java, you can check the following questions:

+7
source

No never.

length is an unsigned number; it cannot be negative.

the first answer to the question denies the second legitimacy of the question.

+3
source

. - . Null .

+1

String.length() legth int, .

javadoc , , .

+1

.

, , length()

public int length() {
    return count;
}

, count -1 int. , .

+1

, , (, -1) , 0

0

Source: https://habr.com/ru/post/1793251/


All Articles