Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
String regionMatches() 
 

In this section, you will get the detailed explanation about the regionMatches() method of String class. We are going to use regionMatches() method of String class in Java.

 

String regionMatches()

                         

In this section, you will get the detailed explanation about the regionMatches() method of String class. We are going to use regionMatches() method of String class in Java. The description of the code is given below for the usage of the method.

Description of the code:

As shown in the example a substring of the specified string object is compared to a substring of the other. If these substrings contain same characters sequence then we get true as output i.e. if the specified subregion of the string matches the subregion of the string argument; otherwise we get false. The substring to be compared begins at index toffset and has length len and that of other substring to be compared begins at index ooffset and has length len. 

Therefore, in the program code given below the characters from 20 through 28 in str1 match characters 25 through 33 in str2 and give true as output. 

However if one of the following is true then only we get false as an output:

  • if toffset is negative.
  • If ooffset is negative.
  • If toffset + len is greater than the length of the String object.
  • If ooffset + len is greater than the length of the other argument.

    Parameters:
    toffset - the starting offset of the subregion in this string.
    ooffset - the starting offset of the subregion in the string argument.
    len - the number of characters to compare. 

    NOTE: This method tests if two string regions are equal or not.

Here is the code of the program: 

public class matchstr{
    public static void main(String args[]){
    String str1 = new String("Java is a wonderful language");
    String str2 = new String("It is an object-oriented language");
    boolean result = str1.regionMatches(20, str2, 256);   
    System.out.println(result);
    }
  }

Output of the program:

C:\unique>javac matchstr.java

C:\unique>java matchstr
true

C:\unique>

Download this example.

                         

» View all related tutorials
Related Tags: java c string class method get int index program to ram e il use indexof in no as m nt

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

my comment is where we can use the regionMatches() method in j2EE techonolagy, it is posiible or not .If it is possible where we can use plese explain
thankyou

Posted by krishnakumari on Wednesday, 09.19.07 @ 10:28am | #27823

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.