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/03 Report--
This article mainly shows you the "sample analysis of String initialization string domain in Java", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and study the "sample analysis of String initialization string domain in Java".
Exercise:
What's the difference between creating a class that contains a string field that is initialized when defined, and another string field that is initialized by a constructor?
Look at this procedure and the results, first of all, clear three knowledge points:
1.String is a reference object
2.equals () compares values
3. "=" is the address of the comparison
String S1 = "abc"; String S2 = "abc"; String S3 = new String ("abc"); String S4 = new String ("abc"); System.out.println (s1==s2); / / true System.out.println (s3==s4); / / false System.out.println (s1==s3); / / false System.out.println (s1.equals (S2)); / / true System.out.println (s1.equals (S2)); / / true
Java has two types of storage types, one is basic types of variables, such as int,float, and the other is reference objects, such as String, various class created by ourselves, arrays, and so on, which require new
It is generally stored in two places, the reference variables of basic types and objects are stored in the stack, and the objects from new are placed in the heap.
In addition, there is a block area constant pool, String S1 = "abc", and "abc" is stored in the constant pool. After we create another String S2 = "abc", the bottom layer of java finds "abc" in the constant pool and lets S2 point to this value and not re-create it. So the first one is true.
Our new is in the heap and will not be checked, so the address is different.
Look at another example.
String S1 = "aaa"; String S2 = "bbb"; String S3 = "aaabbb"; System.out.println (S3 = = S1 + S2); / / false System.out.println (S3 = = ("aaa" + "bbb")); / / true
In this example, S3 = = S1 + S2 when comparing, java opens up a memory in the heap for "S1 + S2", and then splices the strings.
After "aaa" + "bbb" is spliced, it is found that "aaabbb" is equal in the constant pool.
The above is all the content of the article "sample Analysis of String initialization string Fields in Java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.