Java String 可以有多少个字符? [英] How many characters can a Java String have?

查看:44
本文介绍了Java String 可以有多少个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试来自 Sphere Online Judge (SPOJ) 的 The Next Palindrome 问题,我在这里需要找到最多一百万位整数的回文.我想过使用 Java 的函数来反转字符串,但它们会允许字符串这么长吗?

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's functions for reversing Strings, but would they allow for a String to be this long?

推荐答案

你应该能够得到一个长度为

You should be able to get a String of length

  1. Integer.MAX_VALUE 总是 2,147,483,647 (231 - 1)
    (由Java规范定义,数组的最大大小,String类用于内部存储)

  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

最大堆大小的一半(因为每个字符是两个字节)以较小者为准.

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

这篇关于Java String 可以有多少个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆