java-Test Development string

Source: Internet
Author: User

Package J2se;public class Stringdemo {private String demostring= "ceshixiaoyouning";p ublic void TestString () {String dsg= Demostring.concat ("very beautiful");//String addition can also be used to represent System.out.println (DSG); int len=demostring.length ();// The length of the string System.out.println (len); Boolean eq= "ceshixiaoyouning". Equals (demostring);//Compares two strings for equality System.out.println ( EQ); String Sub=demostring.substring (5, 8);//substring, starting with the 5th character, exactly 8 characters, but not containing the 8th character System.out.println (sub); String substring=demostring.substring (5);//substring, starting from the 5th character until the end of the string System.out.println (subString); Boolean SW = Demostring.startswith ("Ceshi");//Determine whether to start with a string System.out.println (SW); Boolean ew=demostring.endswith ("youning"); /Judge the stone at the end of a string System.out.println (EW); int Subindex=demostring.indexof ("ce");//Find out the first occurrence of a substring in a string, If not found, returns -1SYSTEM.OUT.PRINTLN (subindex), int lastindex=demostring.lastindexof ("i");//Find the substring at index of the last occurrence of the string, Returns -1SYSTEM.OUT.PRINTLN (LastIndex) If it is not found; System.out.println (Demostring.touppercase ());//The words in the string all become uppercase System.out.println (Demostring.tolowercase ());//The words in the string all become lowercase System.out.println ("youning". Trim ());//Remove String Subreplace=demostring.replace ("Ceshi", " Hello ");//Replace a string in a string with a new string System.out.println (Subreplace); String Subreplacef=demostring.replacefirst ("I", "HHH");//Converts the first occurrence of a substring into a new string, supporting a regular System.out.println ( SUBREPLACEF); String Subreplacea=demostring.replaceall ("I", "HHH");//Convert all substrings appearing in the string into new substrings, supporting regular System.out.println ( SUBREPLACEA);} public static void Main (string[] args) {Stringdemo s=new stringdemo (); s.teststring ();}}

Operation Result:

Ceshixiaoyouningvery Beautiful
16
True
Xia
Xiaoyouning
True
True
0
13
Ceshixiaoyouning
Ceshixiaoyouning
Youning
Helloxiaoyouning
Ceshhhhxiaoyouning
Ceshhhhxhhhaoyounhhhng

java-Test Development string

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.