Java Learning--the eighth day of basic knowledge--notes

Source: Internet
Author: User

Today's content
How to view API documentation
Keyboard input String data
String class
StringBuilder class


Api
is the class that Java provides to us


Scanner class
Nextline (): Get keyboard input string data


String class
String, which is a constant that cannot be changed after it is defined

Way One:
string s = new String ("abc");
Way two:
Char[] CHS = {' A ', ' B ', ' C '};
string s = new string (CHS);//ABC
Way three:
Char[] CHS = {' A ', ' B ', ' C '};
string s = new string (chs,1,2);//BC
Mode four:
String s = "abc";

Judging function
Boolean equals (Object O): Compares string contents for equality
Boolean equalsignorecase (String str): Determines whether the string contents are equal, ignoring case
Boolean startsWith (String str): Determines whether a string begins with a specified string
Boolean endsWith (String str): Determines whether the string ends with the specified string

Case 1: Impersonate a login, give three chances, and tip a few more times

Get features
int length (): Gets the length of the string, the number of characters
char charAt (int index): Gets the character at the specified index
int indexOf (String str): Gets the index of the first occurrence of the specified string if no return-1 is found
string substring (int index): intercepts a string, starting at index, ending at
string substring (int start,int end): Intercepts a string, starting at the start index, ending at the end index, and noting that the character at the end index is not included

Case 2: Traverse the string (CharAt () method and ToCharArray () method two ways)
Case 3: Count the number of uppercase characters, lowercase alphabetic characters, and numeric characters that appear in a string.

Conversion function
Char[] ToCharArray (): Convert string to character array
String toLowerCase (): Converting a string to a lowercase string
String toUpperCase (): Convert string to uppercase string

Case 4: Keyboard input A string, the first letter of the string into uppercase, the rest is lowercase.

Other features
String trim (): Strips the front and back spaces of a string
String[] Split (String str): Cuts the original string into multiple strings based on the specified string

Case 5: Stitching the data in the array into a string in the specified format
Case 6: String inversion

StringBuilder class
Variable sequence of characters, which is equivalent to a container, any type of data can be added to the

Construction method
StringBuilder ()

Member Methods
Capacity (): Return capacity, theoretical value//understanding
Length (): return lengths, actual values

StringBuilder append (any type): Append Data
StringBuilder reverse (): Invert

Case 1:stringbuilder and string are passed through the method to convert each other
Case 2: Using StringBuilder to stitch an array into a string
Case 3: Using StringBuilder to complete string inversion
Case 4: Judging whether a string is a symmetric string

Java Learning--the eighth day of basic knowledge--notes

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.