How many characters can a Java String have?

后端 未结 7 2140
暗喜
暗喜 2020-11-22 06:56

I\'m trying The Next Palindrome problem from Sphere Online Judge (SPOJ) where I need to find a palindrome for a integer of up to a million digits. I thought about using Java

7条回答
  •  眼角桃花
    2020-11-22 07:11

    You should be able to get a String of length

    1. Integer.MAX_VALUE always 2,147,483,647 (231 - 1)
      (Defined by the Java specification, the maximum size of an array, which the String class uses for internal storage)
      OR

    2. Half your maximum heap size (since each character is two bytes) whichever is smaller.

提交回复
热议问题