In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "how to define strings in Java", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to define strings in Java" article.
Method 1: define the string directly
We can directly define the characters we need in learning and development. Let's take a look at the following related code:
String str= "Hello Java"; String str;str= "You are in my heart!"
When we directly define the characters we need, we need to note that string variables must be initialized before they can be used.
Method 2: use the String class definition
1. String: we represent a sequence of empty characters by initializing a newly created String object.
2. String (String original): initialize a new String object to represent a sequence of characters with the same parameters. Let's take a look at the following code:
String str1 = new String ("Hello Java"); String str2 = new String (str1)
We can see in the code that the values of str1 and str2 are equal.
3. String (char [] value): after assigning a new string, we change all the character array elements in the parameters into strings. Let's take a look at the following code:
Char a [] = {'Hutchison]; String sChar = new String (a); a [1] =' s'
Modify the character array by copying the contents of the character array. And in the code, the value of the sChar variable is the string "hello". Even after the character is created, modifications to the second element of the an array do not affect the value of sChar.
4. String (char [] value,int offset,int count): this method, by reassigning the new String, and it contains characters from a subarray of this array parameter, is the index of the first character of the subarray for the offset parameter, and the count parameter is the length of the stator array. Not only that, the contents of the array have been assigned, but subsequent modifications to the character array will not affect the newly created string, let's take a look at the following example, the code is as follows:
Char a [] = {'Homo]; String sChar=new String; a [1] =' s'
In the code, the value of the sChar variable is the string "ello", and the constructor uses some contiguous elements in the character array to create a string object.
The above is about the content of this article on "how to define strings in Java". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.