By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,866 Members | 1,765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,866 IT Pros & Developers. It's quick & easy.

please explain me this program

P: 36
please any one can explain me this code of region matches program line by line and also the function of region matches.

class regionMatches_Test{

public static void main(String[] args){

String s1= "tsinghua";
String s2="it is TsingHua";
//public boolean regionMatches(int toffset,String other,int ooffset,int len)
System.out.println( s1.regionMatches(0,s2,5,7)) ;

//public boolean regionMatches(boolean ignoreCase,int toffset, String other, int ooffset,int len)
System.out.println( s1.regionMatches(true,0,s2,6,7)) ;

Apr 1 '10 #1
Share this Question
Share on Google+
4 Replies

Expert 100+
P: 2,057, int, int)

0 + 7-1 = 6.
5 + 7-1 = 11
Take characters 0 to 6 of string 1.
Compare to chars 5 to 11 of string 2
Apr 1 '10 #2

P: 36
cant we write it in this way also

it will matches whole of s1 with s2...
Apr 1 '10 #3

Expert 100+
P: 2,057
then you want s1.equals(s2);
or possibly s1.equalsIgnoreCase(s2);
Apr 1 '10 #4

P: 36
s1.equalsIgnoreCase will it ignores if s1 matches s2 if true it will print true and in case it dosent matches it will print fales?isn't it
Apr 2 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.