javase-String Count Lookup

Source: Internet
Author: User

1  PackageCom.it18zhang.day7;2 /**3 * Find the number of Java string occurrences4  * @authorFeigu5  *6  */7  Public classTestcount {8     9 Ten      Public Static voidMain (string[] args) { OneString maxstring = "Woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun"; A         //String maxstring= "Alldlla"; -String minstring = "java"; -         intCount=0; the         //calculate the location of the first occurrence -         intindex=Maxstring.indexof (minstring); -         //find the length of a string -         intlen=minstring.length (); +         //No-1 description contains a lookup string that can enter a while loop -          while(Index!=-1){ +             //Number of occurrences +1 Acount++; at             //calculates the position of the next string intercept (all previous characters are removed) -             intstartindex=len+index; -             //get a new string after intercept -maxstring=maxstring.substring (startIndex); -             //re-determine if the new string contains a string to find -index=Maxstring.indexof (minstring); in         } -System.out.println (minstring+ "Number of occurrences:" +count); to     } +}

javase-String Count Lookup

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.