public Levenshtein(String a, String b) {
        this.distance = 0;

        if (a == null || a.isEmpty()) {
            distance = b.length();
            return;
        }

        else if (b == null || b.isEmpty()) {
            distance = a.length();
            return;
        }

        int[][] dist = new int[a.length() + 1][b.length() + 1];

        for (int i = 0; i <= a.length(); i++)
            dist[i][0] = i;
        for (int j = 1; j <= b.length(); j++)
            dist[0][j] = j;

        for (int i = 1; i <= a.length(); i++)
            for (int j = 1; j <= b.length(); j++)
                dist[i][j] = Math.min(Math.min(
                        dist[i - 1][j] + 1,
                        dist[i][j - 1] + 1),
                        dist[i - 1][j - 1] + ((a.charAt(i - 1) == b.charAt(j - 1)) ? 0 : 1));

        distance = dist[a.length()][b.length()];
    }