[Reprint]java string Fuzzy match (

Source: Internet
Author: User

, you need to do a fuzzy match of the string in Java, because the object length to compare, there is no fixed composition rule, collect the following three methods to solve the problem

Method one, public int indexOf(String str) returns the index where the specified substring first appears in this string. The returned integer is This.startswith (str, k) to trueThe minimum kValue. Parameters: str-Any string. return:If the string argument appears as a substring in this object, the index of the first character of the first such substring is returned, and if it does not appear as a substring, it returns -1。 if (Str1.indexof ("ro") >=0 | | str1.indexof ("EL") >=0 | | str1.indexof ("RO") >=0) {exists} method two, public boolean contains(Charsequence s) returns True when and only if this string contains a sequence of specified char values. Parameters: s-Sequence to search (note: The String class is an entity class that implements the Charsequence interface)  return:If this string contains s, returns True, otherwise returns false for example: Str. contains ("12334" )Note:, meaning that the string "12345" appears in the STR string for any one of the five characters, then it returns true; Method Three, through the regular expression + matchesMethod public Boolean matches(string regex) tells whether this string matches a given regular expression.

The str. Matches (regex) form that calls this method produces exactly the same result as the following expression:

Pattern. matches ( regex , str )
Parameters: regex -A regular expression to match this string
returns: true if and only if this string matches the given regular expression

[Reprint]java string Fuzzy match (

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.