Web | This Site

Java Basics Examples
Java Tutorial
Java Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# Java Examples - String region match

## Problem Description:

How to match regions in strings ?

## Solution:

Following example determines region matchs in two strings by using regionMatches() method.

    public class StringRegionMatch{
       public static void main(String[] args){
          String first_str = "Welcome to Microsoft";
          String second_str = "I work with Microsoft";
          boolean match = first_str.
          regionMatches(11, second_str, 12, 9);
          System.out.println("first_str[11 -19] == "
          + "second_str[12 - 21]:-"+ match);
       }
    }

## Result:

The above code sample will produce the following result.

    first_str[11 -19] == second_str[12 - 21]:-true

Advertisement

Online Image Processing

Indian Baby Names