title: I am trying to get the number of the matching character (I mean how many character are matched) in java
body: <p>So far I have written some code. I have two Strings and I need to compare the string characters and if both Strings are the same, I want to get the number of matches characters.</p>
  
  <p>Below is my code so far. I split the String into a character array and compare the Strings to get the matching character, but I cannot get the number of the matched Strings.</p>
  
  <pre><code>public class labExtra {
      public static void main(String [] args) {
          double l1,l2,biggerN;
          String name1="Siti";
          String name2="Ali";
          l1=name1.length();
          l2=name2.length();
          if(l1&gt;l2) {
              biggerN=l1;
          }
          else {
              biggerN=l2;
          }
          char [] shojib=name1.toCharArray();
          char [] farhana=name2.toCharArray();
          for(int i=0; i&lt;shojib.length; i++) {
              for(int j=0; j&lt;farhana.length; j++) {
                  if(shojib[i]==farhana[j]) {
                      System.out.println(shojib[i]);
                      // ans=new char[shojib[i]];
                      // char [] newary=shojib[i];
                  }
              }
              // System.out.println(ans[i]);
          }
          // System.out.println(newary[0]);
          // System.out.print(biggerN);
      }
  }
  </code></pre>
  
  <p>How can I get how many characters are matched?</p>
  
  <p>In my code one String is <code>siti</code> and the other is <code>ali</code>, so there are 3 matching characters but I don't know how to get this number. Please help me to finish the code. I am really in trouble.</p>
  
  <p>Thanks in advance dude.</p>