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 use Java string

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to use the Java string, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

1. Character

We have seen a total of four character types:

1.1 numeric types, such as 97, 98, 99, etc.

1.2 character types, such as a, b, c, etc.

1.3 Special characters, such as $,%, &, etc.

1.4 invisible characters, such as\ n (line feed),\ r (carriage return),\ t (Tab character), etc.

Characters are essentially numbers, and Java uses the Unicode standard encoding, so each character is mapped to an integer of 0such 65535. For example:

Char word = 97scapeSystem.out.println (word); / / returns the character'a'

Invisible characters have different meanings in different operating systems, for example, the newline symbol is "\ r\ n" under Windows and "\ n" without "\ r" under linux.

two。 String

2.1 creation of string

A string can be thought of as a collection of characters, and we can find the characters in the string by indexing (subscript). There are two ways to create a string:

String word = "abc"; String word = new String ("abc")

Try to avoid the second creation method because of its sexual ability, poor readability and relatively troublesome grammar.

2.2 Properties of strings

In JavaAPI, we can find the definition of String class: public final class String extends Object implements Serializable, Comparable, CharSequence.

Final shows that the String object is a final class that cannot be changed, so there is no way to change the length and content of the string.

The Java runtime maintains a String Pool (String pool). The String pool is used to hold various strings generated at run time, and the contents of the strings in the pool are not duplicated. When we are doing string concatenation, the Java virtual machine does not change the string, but creates a new string constant in String Pool.

The above is all the contents of the article "how to use Java strings". 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.

Share To

Servers

Wechat

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

12
Report