Small white Java Learning path "string"

Source: Internet
Author: User
Tags stringbuffer

You can use the String class and the StringBuffer class.

The string class provides a number of methods for manipulating strings, which are commonly used as follows:

Gets the length of the string: Length ().

comparison string: Equals ( ).

link string: concat ( ).

Extract string: substring ( ).

Search string: IndexOf ().

Split string: Spilt ().

The common StringBuffer class provides the following methods:

Convert to String type: ToString () .

Link string: Append ().

Insert string: Intsert ().

Some cases:

 Public classDemo_1 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubString pwd; @SuppressWarnings ("Resource") Scanner Input=NewScanner (System.inch);  Do{System. out. println ("Please enter user name:"); String name=Input.next (); System. out. println ("Please enter your password:"); PWD=Input.next (); if(Pwd.length () <6) {System. out. println ("password length not enough"); }Else{System. out. println ("Enter the correct"); System. out. println ("you are welcome! "+name);  Break; }        } while(Pwd.length ()! =6); }
Boolean flag;  Public  voidPanduan (String sfz, String sjh,string zj) {flag=false; intIndex=sjh.lastindexof ("-"); if(! (sfz.length () = = -|| Sfz.length () = = -) ) {System. out. println ("the ID number must be 16-bit or 18-bit!"); }    Else if(Sjh.length () < One) {System. out. println ("mobile phone number must be 11 bit!"); }Else if(index!=-1&&index!=0&&index!=4&&zj.length ()! = -) {System. out. println ("The landline number must be 4-bit and the phone number must be 7!"); }Else{System. out. println ("Registration Successful"); Flag=true; }} Call: Public Static voidMain (string[] args) {@SuppressWarnings ("Resource") Scanner Input=NewScanner (System.inch); Practice2 PD=NewPractice2 ();  Do{System. out. println ("Please enter your ID:"); String SFZ=Input.next (); System. out. println ("Please enter your mobile phone number:"); String SJH=Input.next (); System. out. println ("Please enter your landline number:"); String ZJ=Input.next ();        Pd.panduan (SFZ, SJH, ZJ); }  while(pd.flag==false); }

Small white Java Learning path "string"

Related Article

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.