please explain me this program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahmee
    New Member
    • Mar 2010
    • 39

    #1

    please explain me this program

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

    class regionMatches_T est{

    public static void main(String[] args){

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

    //public boolean regionMatches(b oolean ignoreCase,int toffset, String other, int ooffset,int len)
    System.out.prin tln( s1.regionMatche s(true,0,s2,6,7 )) ;

    }
    }
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    http://java.sun.com/j2se/1.4.2/docs/...ing, int, int)

    s1.regionMatche s(0,s2,5,7);
    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
    Last edited by RedSon; Apr 1 '10, 03:37 PM. Reason: fixed url tag

    Comment

    • ahmee
      New Member
      • Mar 2010
      • 39

      #3
      cant we write it in this way also

      s1.regionMatche s(s2);
      it will matches whole of s1 with s2...

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        then you want s1.equals(s2);
        or possibly s1.equalsIgnore Case(s2);

        Comment

        • ahmee
          New Member
          • Mar 2010
          • 39

          #5
          s1.equalsIgnore Case 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

          Comment

          Working...