code: public static String soundex(String str) {
      if (str.length() < 1)
        return ""; // no soundex key for the empty string (could use 000)
      
      char[] key = new char[4];
      key[0] = str.charAt(0);
      int pos = 1;
      char prev = '0';
      for (int ix = 1; ix < str.length() && pos < 4; ix++) {
        char ch = str.charAt(ix);
        int charno;
        if (ch >= 'A' && ch <= 'Z')
          charno = ch - 'A';
        else if (ch >= 'a' && ch <= 'z')
          charno = ch - 'a';
        else
          continue;
  
        if (number[charno] != '0' && number[charno] != prev)
          key[pos++] = number[charno];
        prev = number[charno];
      }
  
      for ( ; pos < 4; pos++)
        key[pos] = '0';
  
      return new String(key);
    }
docs: Produces the Soundex key for the given string.