Java Utililty Methods Array Compare

List of utility methods to do Array Compare

Description

The list of methods to do Array Compare are organized into topic(s).

Method

ListgetRelativeSegments(String[] targetPath, int commonSegments, int discardedSegments)
get Relative Segments
List<String> segments = new ArrayList<String>();
for (int j = 0; j < discardedSegments; j++) {
    segments.add(PARENT);
segments.addAll(Arrays.asList(Arrays.copyOfRange(targetPath, commonSegments, targetPath.length)));
return segments;
StringlongestCommonPrefix(String[] stringArray)
Returns the longest common prefix for the specified strings.
return longestCommonPrefix(Arrays.asList(stringArray));
ListlongestCommonSubsequence(E[] s1, E[] s2)
longest Common Subsequence
int[][] num = new int[s1.length + 1][s2.length + 1]; 
for (int i = 1; i <= s1.length; i++)
    for (int j = 1; j <= s2.length; j++)
        if (s1[i - 1].equals(s2[j - 1]))
            num[i][j] = 1 + num[i - 1][j - 1];
        else
            num[i][j] = Math.max(num[i - 1][j], num[i][j - 1]);
int s1position = s1.length, s2position = s2.length;
...
intlongestCommonSubsequenceAlternate(int[] input)
longest Common Subsequence Alternate
Arrays.sort(input);
int curCount = 1;
int maxCount = 0;
for (int i = 1; i < input.length; i++) {
    if (input[i] - input[i - 1] == 1) {
        curCount++;
    } else {
        curCount = 1;
...
StringlongestCommonSubstring(String s[])
longest Common Substring
if (s.length == 0)
    return "";
String res = s[0];
for (int i = 1; i < s.length; i++) {
    while (true) {
        if (s[i].startsWith(res))
            break;
        if (res.length() == 0)
...