Here you can find the source of levenshteinDistance(String[] a, String[] b)
private static int levenshteinDistance(String[] a, String[] b)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w .j av a 2 s . c om*/ * Straight from Wikipedia */ private static int levenshteinDistance(String[] a, String[] b) { int[][] distance = new int[a.length + 1][b.length + 1]; for (int i = 0; i <= a.length; i++) { distance[i][0] = i; } for (int j = 1; j <= b.length; j++) { distance[0][j] = j; } for (int i = 1; i <= a.length; i++) { for (int j = 1; j <= b.length; j++) { distance[i][j] = minimum(distance[i - 1][j] + 1, distance[i][j - 1] + 1, distance[i - 1][j - 1] + ((a[i - 1].equals(b[j - 1])) ? 0 : 1)); } } return distance[a.length][b.length]; } private static int minimum(int a, int b, int c) { return Math.min(Math.min(a, b), c); } }