Java-regular, the use of two methods in the object, java-object

Source: Internet
Author: User

Java-regular, the use of two methods in the object, java-object

Regular: "." and "\"
"." Point, which represents any character in a regular expression.
"\" Is a conversion character in a regular expression. When we need to describe a special character that has been used by a regular expression, we can use "\" to convert it into the original meaning.
"\" Also has some predefined special content in the regular expression:
\ D: Any number
\ W: Any word character (only numbers, letters, and underscores are allowed)
\ S: any blank character (\ t \ r \ n \ f \ x0B)
\ D: any non-Numeric Character
\ W: any non-word character
\ S: any non-blank character
Character Set [] is used to describe a single character. Square brackets can define the content of this character or describe a range. For example, [abc]: indicates that the character can only be a, B, or c.
[123]: indicates that the character can only be 1, 2, or 3. When we need to describe all lowercase letters, we can use the range [a-z]. this character can be any lowercase letter.
You can also use [0-9] to indicate that the character can be any number.
You can also select from multiple ranges. For example, [a-zA-Z0-9 _] indicates that the character can be any letter, number, and "underline ".
"+": Indicates that the content can appear at least once in a row.
"*": Indicates that the content appears 0-several times
"? ": Indicates that the content appears 0-1 times
{N}: indicates that the content must appear n times.
{N, m}: indicates that the content appears n-m times.
{N ,}: indicates that the content appears at least n times.
() Can regard the content as a whole, () can use "|" to represent or link.
Add "^" at the beginning of the regular expression and add "$" at the end to indicate a whole, but use the default matching overall in Java.

1.1 one of the methods related to regular expressions supported by strings
Boolean matches (String regec)
Use the given regular expression to match whether the current String format meets the requirements of this regular expression and true. The regular expression passed in by the macthes method provided by String is fully matched even if no boundary is added.
1.2 String supports regular expression method 2:
String [] solit (String regex)
Splits the content of the current string according to the part that meets the regular expression, saves several strings after the split into an array, and returns
If the split part is found to be consecutively matched during the split process, an empty string is removed in the middle. However, if the string is matched consecutively at the end of the string, the Null String is ignored.
1.3 The third regular expression method supported by String
String replaceAll (String regex, String str)
Replace the portion of the current string that meets the regular expression with the given string
2.1 Principle of overwriting the tostring method for an object
Generally, when we need to use the toString method of an object, we should rewrite this method, because the handle of the object returned by the method provided by the object: Class Name @ address, in this way, the actual information about object beauty is not obtained.
The string returned by tostring should contain the content (attribute value) of the current object. The specific format content depends on the actual design requirements of the current class.
2.2 equals method of object
The equals method is designed to compare whether the content of the two objects is consistent.
Comparison Principle: Compare the attribute values of two objects. It is not necessarily the same as that of the current class.

 

I am a beginner. If any updates are poor, I would like to thank you!

More highlights will be updated later!

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.