Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Java enumeration how to use the

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use Java enumeration". In daily operation, I believe many people have doubts about how to use Java enumeration. the editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use Java enumerations". Next, please follow the editor to study!

/ * Created by lifei on 16-5-28 * * enumerations are generally not good * / public class RegularExpressionMatching {public static void main (String [] args) {/ / System.out.println (new RegularExpressionMatching () .isMatch ("aa", "a")); / / System.out.println (new RegularExpressionMatching () .isMatch ("aa", "aa")); / / System.out.println (new RegularExpressionMatching () .isMatch ("aaa", "aa")) / / System.out.println (new RegularExpressionMatching (). IsMatch ("ba", "a *")); / / System.out.println (new RegularExpressionMatching (). IsMatch ("aa", ". *")); / / System.out.println (new RegularExpressionMatching (). IsMatch ("ab", ". *"); / / System.out.println (new RegularExpressionMatching (). IsMatch ("aab", "c*a*b")) / / System.out.println (new RegularExpressionMatching (). IsMatch ("", "); System.out.println (new RegularExpressionMatching (). IsMatch (" abcdeff ",". * ")); / / System.out.println (new RegularExpressionMatching (). IsMatch (" a "," ab* ")); / / System.out.println (new RegularExpressionMatching (). IsMatch (" bb "," .bab ")) / / System.out.println (new RegularExpressionMatching (). IsMatch ("aa", "a*aa"); / / true} / * * Recursive implementation * / public boolean isMatch (String s, String p) {if (s = = null) return p = = null; if (p = null) return s = = null Int lenS = s.length (); int lenP = p.length (); if (lenP = = 0) / / regular expression is empty and the string must be empty in accordance with the condition return lenS = = 0 If (lenP = = 1) {/ / regular length is 1, so regular is another character if (p.equals (s)) that cannot be * | p.equals (".") & & s.length () = 1) {return true;} else return false The second character of} if (p.charAt (1)! ='*') {/ / regular is not * if (s.length () > 0 & & (p.charAt (0) = = s.charAt (0) | | p.charAt (0) = ='.')) {/ / if the first character matches Remove one character each and continue to match return isMatch (s.substring (1), p.substring (1)) } return false The second character of} else {/ / regular is * while (s.length () > 0 & & (p.charAt (0) = = s.charAt (0) | | p.charAt (0) = ='.') {/ / if the first character matches if (isMatch (s) P.substring (2)) / / determine whether the data after s and * match, and return successful return true directly if the match occurs. S = s.substring (1); / / otherwise, decrease the length of s in turn until the length of s is empty} return isMatch (s, p.substring (2)); after the length of / / s is empty, judge whether the parts after the * of s and p match}, then the study on "how to use Java enumeration" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report