In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to carry out the powerful String performance analysis under JDK1.5, the content is concise and easy to understand, it can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
String under JDK1.5 is powerful. Let's first take a look at the features of previous versions of String:
The powerful String under JDK1.5 means that String becomes more practical under JDK1.5. String in Java is a special type, which is neither a basic type nor a real variable, but a fixed type, that is, finaltype. So when writing SQL statements or tedious string expressions, in order to improve efficiency, we generally use StringBuffer instead of String. The reason is that a new object C is generated after the operation of string An and string B. As follows:
String a = "mx"; String b = "java"; String c = a + b; System.out.println (c)
The above code has three objects of type String, namely a, b, and a + b. As we said before, because the String type is a fixed value, the java compiler will re-allocate a piece of memory to store the results after the operation. However, this is the way JDK1.5 used to handle String type operations. The String operation is optimized after 1.5. taking the above code as an example, the program compiled with JDK1.4.2 is as follows:
String s = "mx"; String S1 = "java"; String S2 = s + S1; System.out.println (S2)
As you can see, in the compiled program, S2 is still calculated in s + S1, in other words, the third string object is generated. So what does the program compiled by JDK1.5 look like?
String s = "mx"; String S1 = "java"; String S2 = (new StringBuilder ()) .append (s) .append (S1). ToString (); System.out.println (S2)
As you can see, the JDK1.5-compiled code uses StringBuilder to perform string operations. If there is only one operation like the above code, then you will not see any effect (because during the operation, a new StringBuilder object has been created). If there are a large number of operations, the effect will be very obvious. Therefore, when programming with later versions of JDK1.5, you don't have to worry about string addition.
On the Internet, I saw that some netizens used the following methods when testing JDK1.5 's String:
String a = "ab"; String b = "a"; String c = "b"; System.out.println (a = = (b + c))
If true is returned, it is considered to be JDK1.5 's optimization of String. In fact, this is not true, even if the above code is executed under previous versions of JDK1.5, the return value is still true. This is because java has the concept of String pools.
The above content is how to analyze the powerful String performance under JDK1.5. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to 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.