// Get the value from context variable String firstString = (String) context.get("firstString"); String secondString = (String) context.get("secondString"); //String firstString = "kitten"; //String secondString = "sitten"; int cost= 0; firstString = firstString.toLowerCase(); secondString = secondString.toLowerCase(); int[] costs = new int[secondString.length() + 1]; for (int i = 0; i <= firstString.length(); i++) { int lastValue = i; for (int j = 0; j <= secondString.length(); j++) { if (i == 0) costs[j] = j; else { if (j > 0) { int newValue = costs[j - 1]; if (firstString.charAt(i - 1) != secondString.charAt(j - 1)) newValue = Math.min(Math.min(newValue, lastValue), costs[j]) + 1; costs[j - 1] = lastValue; lastValue = newValue; } } } if (i > 0) cost= costs[secondString.length()] = lastValue; } System.out.println(cost); context.put("Levenshtein_distance",cost);