Forum Stats

  • 3,727,834 Users
  • 2,245,473 Discussions
  • 7,853,056 Comments

Discussions

String and character array difference

HariNagarjuna
HariNagarjuna Member Posts: 1
edited September 2019 in New To Java

This is what I understood about difference between strings and array of characters so far and unicode(U+0000 to U+FFFF).

1.Unicode of BMP is combination of 0's and 1's and gives 65,536(2^16 or 16^4) characters.

2.character array can only contain this 65,536 BMP unicode characters.

3.String can have things other than unicode characters in BMP(65,536 characters).

please correct me if I am wrong.

Answers

  • OrhanCemalDuru
    OrhanCemalDuru Member Posts: 6
    edited September 2019

    Character encoding tables vary, the class String is, as far as I am concerned, capable of displaying, formatting, and manipulating characters of any encoding type.

    The numbers you give relate to INTEGER_MAX value which also applies to memory allocation of arrays (taking into account the data type). For instance if you have a byte array of length INTEGER_MAX, you get INTEGER_MAX bytes of memory allocated for use. I'm not sure if all encoding tables use a fixed amount of memory, ones I know use a single byte for a single character. So there are 2^8 possible different representations for each character set. That makes 256 unique representations.

  • nihitthakkar
    nihitthakkar Member Posts: 110 Blue Ribbon

    The basic difference between string and character array are: String refers to a sequence of characters while represented as a single data type. Character Array is a sequential collection of data type char. Strings are immutable and Character Arrays are mutable. Built in functions are provided in Strings but it is not provided in Character Array.

  • nihitthakkar
    nihitthakkar Member Posts: 110 Blue Ribbon

    The basic difference between string and character array are: String refers to a sequence of characters while represented as a single data type. Character Array is a sequential collection of data type char. Strings are immutable and Character Arrays are mutable. Built in functions are provided in Strings but it is not provided in Character Array.

Sign In or Register to comment.