Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse String

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about how to analyze String, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

In java, the String class is a very special class. First, it is a final class, that is, immutable. Second, it has a String pool that other classes do not have!

String s=new String ("hexiaozi")

How many new objects will be generated by such a statement? Many people usually don't pay attention to this kind of problem. Today, after listening to teacher Feng's lecture, I borrowed flowers to offer Buddha to tell you my understanding!

Because the String class has a String pool, when you create an object, you will first check whether there is an object with the content "hexiaozi" in the String pool, and if not, an object with the content "hexiaozi" will be created in the String pool!

Because a new is used to create objects, as we all know.

The created object will be placed in the heap! And the reference s of the object here obviously points to the object in heap!

To sum up, this statement will produce several new objects, which should be analyzed according to the context. If the object "hexiaozi" already exists in string pool, only one object will be generated in memory heap, otherwise one object will be generated in String Pool and one object in memory heap!

By the same token, if:

String S1 = "hexiaozi"

This statement will only check whether the content is "hexiaozi" in String Pool, if so, no new object will be generated, if not, a new object will be generated in String Pool!

The above is how to analyze String, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report