In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to convert big data string". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought slowly and deeply. Let's study and learn "how to convert big data string"!
Immutable string:-String. The string itself cannot be changed, regardless of the reference to the string.
String S1 = "1000phone"
Variable string:-StringBuilder/StringBuffer. The string itself can change, regardless of references to mutable strings
StringBuffer sBuffer = new StringBuffer ("1000phone")
The immutable string itself is a constant, stored in the constant area and stored in a special area in the heap area.
Characteristics of string constants: only one string constant is allowed to be stored in the constant area.
String s = "1000phone"; / / immutable string
When executing s, it will go to the constant area to find a string called 1000phone. If there is a direct request for s to save his address, if not, it will open up a space to store 1000phone in the constant area.
String S3 = new String ("1000phone")
When executing S3, because of the new, there must be a space in the heap now, and the 1000phone is passed to the object as a parameter. Saved in a String of the object
Using equals to compare String
two。 Conversion:
Convert a character array to a string
Char [] arr = {'pause, pause, clue, chop, roll, chop, chew, chew
String string1 = new String (arr); / / string1 = phone
Convert a string to a character array
Char [] arr1 = string.toCharArray ()
System.out.println (arr1)
Convert a byte array to a string
/ / String (byte [] bytes)
/ / String (byte [] bytes, int offset, int length)
/ / String (byte [] bytes, String charsetName) / / converts an array of bytes into characters using the specified encoding
Byte [] bytes = {97199899100}
String string3 = new String (bytes)
System.out.println (string3); / / abcd
Convert a string to a byte array
/ / byte [] getBytes ()
Byte [] bytes1 = string3.getBytes ()
Convert basic data types to strings
/ / String.valueOf ()
String string4 = String.valueOf (true)
System.out.println (string4); / / true
Substring:
/ / contains the start position, excluding the end position, to the first bit of the end position
String substring (int beginIndex, int endIndex)
Case conversion
String toLowerCase (); / / convert to lowercase
String toUpperCase (); / / convert to uppercase
Compare two strings in dictionary order
Dictionary order: compare the current two characters according to the ASCII table, and the larger ASCII code is considered to be the big character.
Rule: compare from the first character on the left
If the current character is different, the string with large ASCII is considered to be large, and the following characters stop comparing.
Specific rules for current character comparison: use the preceding character-the following character, to return the difference. If it is a negative number, the preceding string is less than the latter. On the contrary, the front one is big.
If the current character is the same, compare the second character and push it back in turn. If the character is the same in the end, the two strings are considered to be equal, and the difference returns 0.
"1000PHone" .compareto ("1000PHone"); / / 0
"1000AHone" .compareto ("1000BHone"); / /-1
"100000" .compareto ("100th"); / /-3
Variable string:
String buffer .StringBuffer / StringBuilder
Difference:
StringBuffer: appears in jdk1.0, is thread-safe, taking into account thread safety issues
StringBuilder: when it appears in jdk1.5, it is not thread safe and thread safety issues are not considered.
Note: when not considering thread safety, try to use StringBuilder because of its high speed and efficiency
Use:
StringBuffer sBuffer = new StringBuffer ()
/ / 1. Storage:
/ / StringBuffer append (boolean b) insert from last
SBuffer.append ("abcd"); / / abcd
/ / StringBuffer insert (int offset, boolean b) insert from the specified location
SBuffer.insert (4123)
System.out.println (sBuffer); / / abcd123
/ / 2. Delete:
/ / StringBuffer delete (int start, int end) delete part of the string
/ / StringBuffer deleteCharAt (int index) Delete a character
System.out.println (sBuffer.deleteCharAt (4)); / / abcd23
System.out.println (sBuffer.delete (2) 4); / / ab23
/ / 3. Modify:
/ / StringBuffer replace (int start, int end, String str) replaces the specified substring
/ / void setCharAt (int index, char ch) modifies one character
SBuffer.replace (1,3, "ab"); / / aab3
/ / 4. Get:
/ / char charAt (int index)
System.out.println (sBuffer.charAt (0)); / / a
/ / returns the subscript of the specified substring from left to right
/ / int indexOf (String str)
System.out.println (sBuffer.indexOf ("ab")) / / 1
/ / returns the index of the first occurrence of the specified substring in this string, starting with the specified index.
System.out.println (sBuffer.indexOf ("ab", 0); / / 1
System.out.println (sBuffer.indexOf ("ab", 2); / /-1
/ / int lastIndexOf (String str)
/ / returns the index of the specified substring (counting from the right) when this string first appears
System.out.println (sBuffer.indexOf ("ba")); / /-1
System.out.println (sBuffer.indexOf ("ab")) / / 1
/ / int lastIndexOf (String str, int fromIndex)
/ returns the index of the last occurrence of the specified character in this string, starting at the specified index.
System.out.println (sBuffer.indexOf ("ab", 1); / / 1
/ / 5. Reverse:
/ / StringBuffer reverse ()
System.out.println (sBuffer.reverse ()); / / 3baa
Thank you for your reading, the above is the content of "how to convert big data string". After the study of this article, I believe you have a deeper understanding of how to convert big data string. The specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.