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