The maximum length of string in Java

2010-11-08  来源:本站原创  分类:Java  人气:110 

In the cpp in order to portability, string length is the string:: size_type, suddenly wanted to know the java string length is the maximum allowed number. String to see the source:

public final class String
110 implements, Comparable <String>, CharSequence
111 {
112 / ** The value is used for character storage. * /
113 private final char value [];
115 / ** The offset is the first index of the storage that is used. * /
116 private final int offset;
118 / ** The count is the number of characters in the String. * /
119 private final int count;

String is a char array in the form of internal storage, the length of the array is int type, then the maximum length of String is Integer.MAX_VALUE out. Also, because the characters in java based on 16-bit memory, so it takes about 4GB of memory to store the maximum length of string. But this is just a string variable, if a string literal (string literals), such as "abc", "1a2b" and the like written in the code string literals, then the maximum length allowed depends on the string stored in the constant pool size, that is, the format string in the class file storage format:

CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes [length];

u2 is an unsigned 16-bit integer, so in theory the maximum allowed length of string literal is 2 ^ 16 = 65536. Nevertheless, the actual tests show that the maximum length of only 65,534, more than on the compilation error, and are interested can try to write sections of the code.

  • The maximum length of string in Java 2010-11-08

    In the cpp in order to portability, string length is the string:: size_type, suddenly wanted to know the java string length is the maximum allowed number. String to see the source: public final class String 110 implements, Compar

  • varchar2 and nvarchar2 and the maximum length of char 2010-09-30

    1. CHAR is fixed length, while the VARCHAR2 length can vary, for example, store the string "abc", for CHAR (20) That you store the character will account for 20 bytes (including null character 17), while the same VARCHAR2 (20) only takes 3 bytes

  • [Change] What is the maximum length of a URL? 2010-08-14

    Transfer from: 2006-10-13: Although the Specification of the HTTP Protocol does not specify any maximum Length, practical limits are imposed by Web Browser and Server Software. Microsoft Internet Expl

  • Review: String to Java objects into the tool library (change) 2010-09-20

    Original: Joda Time fame of Stephen Colebourne before his release on a Java library joda Convert , in his blog, first launched a small range of arguments , This library can be carried out based annota

  • The maximum length Url 2010-11-11

    In the http protocol, in fact, is not to restrict the length of url, often the maximum length of url and the user's browser and Web server related to a different browser, to accept the maximum length is often not the same, of course, not the same Web

  • The maximum length of the request the browser url 2011-05-27

    The browser, the maximum length of HTTP Get request URL is not the same types of popular browsers, and more than the maximum length of maximum length and submitted as follows: IE6.0: url maximum length of 2083 characters could not be submitted later

  • How to judge a string in Java is the number of all 2011-07-29

    You can use regular expressions: public boolean isNumeric(String str) { Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(str); if (!isNum.matches()) { return false; } return true; } but this method is not safe, do not

  • Maximum length of varchar in MySQL How much? 2011-02-22

    Asked a question: MySQL in the maximum length of varchar is how much? This is not a fixed number. This paper briefly explain the limitations rules. 1, limit rules Field limit when the field definition has the following rules: a) storage limit varchar

  • Will. Net pass over the binary string into java to byte [] 2010-12-23

    Today, a colleague called to use java to write. Net of webService a method, this method will return the file contents of the binary string. He used the method as follows: Convert.ToBase64String((byte[])dr["attachment"]); I get here with the java

  • Convert string to java.sql.Date type 2010-03-29

    java in a String-type time-type time conversion JAVA.SQL.DATE added to the SQL Server's datetime type field-ri (collection will be a time to input String tm = "1999-12-22" (Time) Converted into Date type (java.sql.Date is not a java.util.Date) A

  • Revised json string generated java class 2010-01-04

    Reprinted: Remember wrote a json string on the generated java class, because the use is relatively small, so it does not go into details about the recent study and EXT, in its use has also highlighted jso

  • String Class java thread 2010-07-11

    String class in java is not allowed to be overridden In the thread, but also the various methods which are safe, will not be the case variable ToString this will not run as half the time to stop. Such as the following code fragment public void run(){

  • String reverse (JAVA) 2010-08-15

    / ** * String reverse (Stack) * * @ Param str * @ Return * / public String reverseStr (String str) ( char [] stack = new char [str.length ()];// stack / / Into the stack for (int i = 0; i <str.length (); i + +) ( stack [i] = str.charAt (i); ) / / The

  • Date and string conversion java 2010-09-14

    1 SimpleDateFormat take a leading role, and how to format all rows import java.util.Date; import java.text.SimpleDateFormat; public class Demo ( public static void main (String [] args) ( Date now = new Date (); SimpleDateFormat f = newSimpleDateForm

  • java.util.Date is converted to String format java.text.SimpleDateFormat 2010-12-29

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String today = df.format(new Date()); The Doc in java.text.SimpleDateFormat format specification in detail

  • Increase in demand up to the maximum length sequence 2011-05-01

    Problem Description A sequence of numbers bi, when b1 <b2 <... <bS, we call this sequence is increasing. For a given Sequences (a1, a2, ..., aN), we can get some upward sequence (ai1, ai2, ..., aiK), where 1 <= i1 <i2 <... < iK <=

  • 读取excel生成String[]数组java 2014-12-11

    String excelFileName = "d:\\dy.xls"; List<String[]> list = readExcel(new File(excelFileName), 1); int lsize=0; for (int i = 0; i < list.size(); i++) { lsize=lsize+list.get(i).length; } String[] str1 = new String[lsize]; for (int i = 0;

  • String.intern () java constant pool 2010-04-22

    When the intern method is invoked, if the pool already contains a string equal to this String object (with the equals (Object) method to determine), then returned to the pool of strings. Otherwise, this String object is added to the pool, and returns

  • Read the form of a string XML JAVA 2010-10-08

    StringReader reader = new StringReader (requestXml); InputSource inputSource = new InputSource (reader); SAXBuilder saxBuilder = new SAXBuilder (); try ( Document documen = (inputSource); Element root = documen.getRootElement (); Sys

  • Error: Package Reference constraint name maximum length is limited to 30 character 2011-06-13

    Causes and solutions: SQL result table generated when the pass was built, the problem is the default setting, change under it. Adjust the following parameters: Database => Edit current DBMS Database type:: Script \ Objects \ MaxConstLen value => 255