Class LevenshteinDistance

java.lang.Object
Services.Dependencies.LevenshteinDistance

public class LevenshteinDistance extends Object
Utility class to calculate the Levenshtein distance between two strings.

The Levenshtein distance is a measure of the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into another.

  • Constructor Details

    • LevenshteinDistance

      public LevenshteinDistance()
  • Method Details

    • levenshteinDistance

      public static int levenshteinDistance(String s1, String s2)
      Computes the Levenshtein distance between two strings.
      Parameters:
      s1 - the first string
      s2 - the second string
      Returns:
      the number of edits required to convert s1 into s2
    • dist

      public static int dist(char[] s1, char[] s2)
      Computes the Levenshtein distance between two character arrays.

      This implementation uses a memory-efficient approach by storing only the previous row of the distance matrix.

      Parameters:
      s1 - the first character array
      s2 - the second character array
      Returns:
      the number of edits required to convert s1 into s2