Tuesday, 29 March 2016

Java Tutorial : Java String [regionMatches method example]


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=3jw46X-otzc&list=UUhwKlOVR041tngjerWxVccw

RegionMatchesDemo.java
public class RegionMatchesDemo
{
    public static void main(String[] args)
    {
        String searchMe = "Red Eggs and Ham";
        String findMe = "Eggs";
        int searchMeLength = searchMe.length();
        int findMeLength = findMe.length();
        boolean foundIt = false;
        /*
         * The program steps through the string referred to
         * by searchMe one character at a time. For each
         * character, the program calls the regionMatches
         * method to determine whether the substring
         * beginning with the current character matches the
         * string the program is looking for.
         */
        for (int i = 0; i <= (searchMeLength - findMeLength); i++)
        {
            if (searchMe.regionMatches(i, findMe, 0, findMeLength))
            {
                foundIt = true;
                System.out.println("foundIt = " + foundIt);
                System.out.println(searchMe.substring(i, i
                        + findMeLength));
                break;
            }
        }
        if (!foundIt)
            System.out.println("No match found.");
    }
}
Output
foundIt = true
Eggs
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/StringDemo_regionMatches_example_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_regionMatches_example_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/219b10088440d75a7105e6bff5bbab9e88ad9a80/BasicJava/StringDemo_regionMatches_example_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment