Java字符串中的最大字符数 [英] Maximum number of characters in a string in java

查看:38
本文介绍了Java字符串中的最大字符数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要尝试提高性能,我计划使用包含大量字符的字符串.我想知道是否有任何尺寸可以认为是最佳尺寸.例如,如果我声明一个可以容纳5000个字符串的字符串数组,并且每个单元格中的字符串都包含5000-7000个字符,那么我在考虑是否会降低性能.

To try something with performance improvement, I am planning to use a string containing large number of characters. I want to know if there is any size which can be considered optimal. For ex if I declare a string array which can hold 5000 strings and if string in each of the cell holds 5000-7000 characters, I am thinking whether there is any kind of performance degrading.

请咨询.

推荐答案

由于将字符串文字存储在常量池中,因此将其限制为65535个字节.我不确定运行时间字符串是否有限制,除了由于数组寻址而明显的限制2 ^ 31-1之外.

String literals are constrained to 65535 bytes due to being stored in the constant pool. I'm not sure if there is a limit on run time strings, apart from the obvious limit of 2^31-1 due to array addressing.

编辑以清除错误:这是65535字节(采用Utf8修改版编码).它与普通的Utf8相同,除了null字符是两个字节,并且BMP之外的字符使用代理对(6个字节而不是4个字节).如果您只是在做ascii,那么每个字符只有一个字节.

Edit to clear things up: This is 65535 bytes in Modified Utf8 encoding. It's the same as normal Utf8 except that the null character is two bytes and characters outside the BMP use a surrogate pair (6 bytes instead of 4). If you're just doing ascii, then this is just one byte per character.

这篇关于Java字符串中的最大字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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