String We often use it in development and learning , But yes String The value range of type is not clear .
String The bottom is char Array , The length limit is not indicated .java You can specify the length of the array , If it is not specified, it is specified with the actual element
private final char value[];
From the bottom method length() It can be seen that , The return is int type .
public int length()
And in the java in ,int The maximum value of 2^31-1 = 2147483647, It's also value[]
The length of the array is 2^31-1 .
But when defining a 10 Ten thousand character string post compilation ,jvm It will prompt for an error :java: Constant string too long
Because jvm The compilation specification makes restrictions , At compile time ,jvm Will put literal strings into the constant pool , and JVM in class The document is standardized .
All entries in the constant pool have the following format .
cp_info{
u1 tag;
u2 info[];
}
among
u1 tag
Indicates a flag , Represents the type of the current constant ;u2 info[]
from tag Determine the contents of the array .( See 《Java Virtual machine specification 》 4.4 chapter )notes : stay class In file , There are special data types used to represent Class The content of the document , Include u1、u2、u4, Represent the 1、2、4 Unsigned number of bytes ; Every Class All documents are made by 8 A byte stream in bytes , all 16 、 23 、 64 Bit length data will be constructed as 2 individual 、 4 individual 、 8 individual 8 In byte units ( See 《Java Virtual machine specification 》 The first 4 Chapter )
tag The corresponding items are .
constant type | value |
---|---|
CONSTANT_Class | 7 |
CONSTANT_Fieldref | 9 |
CONSTANT_Methodref | 10 |
CONSTANT_InterfaceMethodref | 11 |
CONSTANT_String | 8 |
CONSTANT_Integer | 3 |
CONSTANT_Float | 4 |
CONSTANT_Long | 5 |
CONSTANT_Double | 6 |
CONSTANT_NameAndType | 12 |
CONSTANT_Utf8 | 1 |
CONSTANT_MethodHandle | 15 |
CONSTANT_MethodType | 16 |
CONSTANT_InvokeDynamic | 18 |
String The corresponding is CONSTANT_String term , The specific definition format is
CONSTANT_String_info{
u1 tag;
u2 string_index;
}
u1 tag
The value of is CONSTANT_String(8);u2 string_index
The value of must be a valid index to the constant pool table , And the entry at this index must be CONSTANT_Utf8_info structure
String is based on CONSTANT_Utf8 The type is represented in the constant pool .class In file CONSTANT_Utf8 Specific definition format ,
CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes[length];
}
u1 tag
The value of is CONSTANT_Utf8(1);CONSTANT_Utf8_info The content ofu2 length
Property to determine the length ;u1 bytes[length]
Representing a string value byte Array
among u2 representative 2 Unsigned byte units , and 1 Bytes 8 position (bit),2 One is 16 position ,16 The highest bit indicates 2^16 - 1 = 65535, And because virtual machines need 1 An instruction of bytes is used as the end instruction , So its real effective range is 【0-65564】. Of course, this range is the valid range of compilation time , The string spliced at runtime is in the maximum range of shaping .
String Length limit ? More articles about
- java String Length vs varchar Length matching understanding ( Character and byte length understanding )
java String Length vs varchar Length matching understanding ( Character and byte length understanding ) string Medium length() length , The return is char The number of , Every char Can store any type of text and characters in the world , One char ...
- string Length problem
Original address : https://toutiao.io/shares/2029578/url String yes Java One of the most important data types in , In addition to the basic data types ,String Is the most widely used , however , About ...
- C# And the type of field in the database Int16(short), Int32(int), Int64(long) Value range of 、 difference .string length
At first, I saw Int16, Int32, Int64 These three types are a little strange , Why the whole number ending , It's weird . Yesterday we thought of each other , ms This is to let you know at a glance how much space this data type occupies . Int8, etc. ...
- Java int turn string If the length is insufficient, fill it on the left 0
This requirement has been used in recent projects , I tried both methods to achieve Method 1 :( recommend ) String s=String.format("%010d", 123)//123 by int type ,0 On behalf of the previous to be added ...
- I said, "master strings." , The interviewer asked me Java Medium String Is there a length limit ?
String yes Java One of the most important data types in , In addition to the basic data types ,String Is the most widely used , however , About String, In fact, there are many things that are easy to be ignored . As we are going to discuss in this article :Ja ...
- I said I'm good at strings , The interviewer asked me Java Medium String Is there a length limit !?| With video explanation
About String Is there a length limit , I've written a separate article and analyzed it before , Recently, I took the time to review this issue , I found that I had some new knowledge . So I'm going to rearrange the content . This time, based on the previous article, in addition to adding some verification ...
- Swift3 - String character string 、Array Array 、Dictionary The use of dictionaries
Swift Related knowledge , This essay is character string . Array . Simple use of dictionaries , Have understanding . I hope you can correct the mistakes . ///************************************************** ...
- string Black science and technology
1. string Object definition, initialization, read and write string s1; Default constructor ,s1 For the empty string string s2(s1); take s2 Initialize to s1 A copy of string s3("valuee&qu ...
- Java Summary series :Java String
String As Java The most common reference type in , Relatively speaking, they are basically familiar with , Whether in the usual coding process or in the written interview ,String They are very popular , However , In the use of String In the process , There are more details to pay attention to . 1 ...
- thorough JVM- of String Memory leak
What is memory leak ? So called memory leak , It refers to the situation that the program fails to release the memory that is no longer used due to negligence or error , He is not saying that physical memory has disappeared , It refers to that objects that are no longer used occupy memory and are not released , As a result, the available memory keeps decreasing , It may eventually lead to internal ...
Random recommendation
- WPF introduction :XAML
XAML yes WPF Technology is used exclusively in design UI Language XAML The greatest advantage is that UI Separation from logical code Create the first one WPF Applications VS Default generated WPF Project solutions Properties: It mainly contains a part of the program used ...
- js Function.call
Before mentioning the above concepts , First of all, I want to talk about javascript Implicit parameters of functions in :arguments Arguments This object represents the function being executed and the parameters of the function calling it . [function.]arguments ...
- Subversion Detailed explanation
Subversion characteristic 1. Versioned directory You can track changes to the directory tree . Files and directories are versioned ,SVS Only a single file can be tracked : 2. Accurate file tracking Files and directories can be increase . Copy . Change of name , Solved the problem of the same name and Irrelevant documents ...
- MVVM Mode application Introduction to
M-V-VM (1)M: namely Model, Models abstracted from the real world : V: namely View, View , Interface , The interface interacts with the user input device : however View And Model How to interact ? Binding Then it can work , ...
- zepto js Source code Reading
/* Zepto v1.0-1-ga3cab6c - polyfill zepto detect event ajax form fx - zeptojs.com/license */ ;(funct ...
- python_ How to split a string with multiple separators ?
Case study : Split a string according to the separator , This character contains various separators , as follows s = '12;;7.osjd;.jshdjdknx+' among ; . + The separator is What are the solutions ? Method 1: adopt str.spl ...
- About python in phantomjs Unable to access the processing of the web page
The system used by the author is linux ubuntu, Recently, in the process of learning crawler, I met a crazy problem , I try to use selenium Add phantomjs When I come to the website ,Pythony Always hint selenium Cannot find element ...
- [LeetCode] Reordered Power of 2 Reorder as 2 Multiple
Starting with a positive integer N, we reorder the digits in any order (including the original order ...
- How to configure Bitbucket Of ssh
stay bitbucket Upper use https agreement , There are often errors when submitting code , It's very irritating , But with ssh It's a lot more convenient . Here's how to set up ssh Methods :1. Run in terminal ssh-keygen.2. Then all the way ente ...
- rtf Garbled solutions
First , Elaborate rtf, Rich text format document , At present, it is commonly used as a template : The problem I have is rtf The text display after replacement in is normal ,rtf Go straight to pdf It's not normal , adopt notpad++ Found after opening rtf Its content code is something I have never seen ( ...