code: public static int[][] levenshteinDistance(String wordForm, String lemma) {
  
      int wordLength = wordForm.length();
      int lemmaLength = lemma.length();
      int cost;
      int[][] distance = new int[wordLength + 1][lemmaLength + 1];
      
      if (wordLength == 0) {
        return distance;
      }
      if (lemmaLength == 0) {
        return distance;
      }
      //fill in the rows of column 0
      for (int i = 0; i <= wordLength; i++) {
        distance[i][0] = i;
      }
      //fill in the columns of row 0
      for (int j = 0; j <= lemmaLength; j++) {
        distance[0][j] = j;
      }
      //fill in the rest of the matrix calculating the minimum distance
      for (int i = 1; i <= wordLength; i++) {
        int s_i = wordForm.charAt(i - 1);
        for (int j = 1; j <= lemmaLength; j++) {
          if (s_i == lemma.charAt(j - 1)) {
            cost = 0;
          } else {
            cost = 1;
          }
          //obtain minimum distance from calculating deletion, insertion, substitution
          distance[i][j] = minimum(distance[i - 1][j] + 1, distance[i][j - 1] + 1, distance[i - 1][j - 1] + cost);
        }
      }
      return distance;
    }
docs: Computes the Levenshtein distance of two strings in a matrix.
  Based on pseudo-code provided here:
  https://en.wikipedia.org/wiki/Levenshtein_distance#Computing_Levenshtein_distance
  which in turn is based on the paper Wagner, Robert A.; Fischer, Michael J. (1974),
  "The String-to-String Correction Problem", Journal of the ACM 21 (1): 168-173
  @param wordForm the form
  @param lemma the lemma
  @return the distance