Jerry Education 7

Source: Internet
Author: User

2016.08.08

Add a breakpoint, follow the debug mode, press F6 step-by-step down, the right side display error message, looking for the wrong place.

String

Double quotation marks are the strings that are generated.

All data types can be converted to strings.

To store a string using a String object:

String s= "Hello World";

String S=new string ();

String S=new string ("Hello World");

String s1= "123456";

String s2= "123456";

System.out.println (S1==S2);

The output is: true. The reason is: S1 in the string constant pool to request a space, the value of 123456,S2 is also 123456, no re-application of space, because it is a reference data type string, so the same address is the same, so the result is true.

String S1=new string ("123456");

String S2=new string ("123456");

System.out.println (S1==S2);

The output is: false. The reason is that both S1 and S2 have requested a space in the string constant pool, are assigned a value of 123456, the spatial address is different, so the result is false.

Determines whether two strings are equal, using the Equals method.

The string class is located in the Java.lang package and has rich methods (calculating the length of a string, comparing strings, connection strings, extracting strings).

The string class provides the length () method, which determines how long the string is.

The Equals method compares the contents of a string for equality.

Equals (): Checks whether the characters that make up the string contents are exactly the same.

Difference:

= =: When both sides are basic data types, the comparison is whether the value is the same, both sides of the reference data type, the comparison is the space address.

Equals (): Compares whether the contents of the two sides are the same.

String s1= "ABCDEFG";

S1.touppercase ();

The toUpperCase () method reverses the string converted to uppercase.

The toLowerCase () method reverses the string converted to lowercase.

The Equalsignorecase () method ignores the case of two strings.

Connection of strings

String s3= "Hello";

S3=s3.concat ("World");

System. out. println (S3);

The Concat method implements concatenation of strings.

Determine if @ and. is present in the string

Email.contains ("@"); Returns a Boolean type.

public int indexOf (int ch) and public int indexOf (string value) search for the first occurrence of the character ch (or string value).

public int lastIndexOf (int ch) and public int lastIndexOf (string value) search for the last occurrence of the character ch (or string value).

public int substring (int index): extracts the string portion starting from the position index.

public string substring (int beginindex,int endIndex): Extracts the string portion between Beginindex and EndIndex.

public string Trim (): Returns a copy of the call string with no spaces before or after it (with spaces in the middle).

The string class provides the split () method, splits a string into substrings, and returns the result as an array of strings.

Jerry Education 7

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.