Home>

Nice to meet you. In new employee training, I learned that when using the Java substring () method, the index number is assigned after the first character of the string is number 0. Is that a string an array of characters?

If i write in C

char salut [20] = "Hello World!";
char ciao [20] = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘’,
                 ‘W’, ‘o’, ‘r’, ‘l’, ‘d’, ‘!’};

Can the two variables salut and ciao be essentially the same in this case?

  • Answer # 1

      

    A character string is an array of characters?

    In C languageYes, Java strings areStringobjects, notarrays. It is just a convenience to make it easy to access each character.

      

    Can the two variables salut and ciao be essentially the same in this case?

    ciaohas no end'\ 0'.

  • Answer # 2

    In the C language, there is no type called string.
    I just call the zero-terminated character array for convenience.

  • Answer # 3

      

    I learned that when using Java's substring () method, the index number is assigned after the first character of the string is 0th.

    StringThesubstring ()class'ssubstring ()method is simply expressed as an "index" in the explanation. is not it. It is not intended to be an array.
    And when referring to the middle part where the characters are lined up, the "what character" that human thinks is usually called "first character" in the case of the first character, for example.Stringsubstring ()method of the/code>class, the first character must be "0th character", so the first character is also intended to be specified in the argument Please understand that sometimes you have to specify0.