title: How do i make more elegant function to get equal letters from 2 strings in Java?
body: <p>I could not find standard string-function in Java to find matching letters in 2 strings.</p>
  
  <p>Do you know how to make the below code smaller/refactor it using some standard functions?</p>
  
  <p>I only made simplest function: compare every letter of first string to every letter of second string.</p>
  
  <pre><code>public static void compare_letters(String name1, String name2) {
    int equal_letters = 0 ;
    for(int i = 0 ; i &lt; name1.length() ; i++) {
      String current_letter  = name1.substring(i,i+1);
  
      for(int j = 0 ; j &lt; name2.length() ; j++) {
        if(current_letter.equals(name2.substring(j,j+1)))
          equal_letters++ ;
      }
    }
    System.out.println("num of equal letters " + equal_letters) ;
  }
  
  public static void main(String args[]) {
    String n1 = "abc";
    String n2 = "bcd";
    compare_letters(n1,n2);
  }
  </code></pre>
  
  <p>How do i refactor it to make it smaller - I m sure there must be some <strong>elegant way</strong> to do this! This is so common procedure - there must be elegant way to do that!</p>