Java===java Basic Learning (4)---string manipulation

Source: Internet
Author: User

The string manipulation in Java is roughly the same as in Python, and what you need to be familiar with is a concrete form of operation.

For the use of specific APIs, see: java=== String Common API Introduction (GO)

 PackageTestbotoo; Public classShuzhileixingzhuanhuan { Public Static voidMain (string[] args) {String greeting= "Hello word"; //the substring method of the string class enables the extraction of a string and extracts a substring. String s = greeting.substring (3,8);  System.out.println (s); //The result is lo wo//concatenation of Strings        intA = 13; String C= "Hahhah my"; String D= A +C;        System.out.println (d); //Immutable String//For example, change the greeting to help!Greeting = greeting.substring (0,3) + "p!";   System.out.println (greeting); //help!                         intn =greeting.length ();        SYSTEM.OUT.PRINTLN (n); intCpcount = Greeting.codepointcount (0, N);                System.out.println (Cpcount); StringBuilder Builder=NewStringBuilder (); Builder.append ("Sdasada"); Builder.append (123); System.out.println (intlength ()); String completedstring= Builder.tostring ();//call the ToString method to get a string objectSystem.out.println (completedstring); }}

Check if strings are equal
expression: s.equals (t)
returns True if they are equal. Returns False if you do not want to wait
* * Note that it is not possible to use the = = operator to detect equality of two strings!
        
empty string and null string
* Empty Strings "" is a string of length 0
*null String, there is currently no object associated with the variable.
You can use the following code to check whether a string is empty
if (str.length () = = 0)
or
if (Str.equals (""))
You can use the following code to check if NULL
if (str = = null)

Java===java Basic Learning (4)---string manipulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.