List<String> (@NotNull String path1, @NotNull String path2) { List<String> result = new ArrayList<>(); List<String> path1Arr = pathToPathList(path1); List<String> path2Arr = pathToPathList(path2); if (path1Arr.size() > path2Arr.size()) { path1Arr = pathToPathList(path2); path2Arr = pathToPathList(path1); } List<String> arrayList = new ArrayList<>(); for (int i = 0; i < path1Arr.size(); i++) { if (path1Arr.get(i).equals(path2Arr.get(i))) { arrayList.add(path1Arr.get(i)); } else { break; } } if (arrayList.isEmpty()) return arrayList; String commonPath = pathListToPath(arrayList); result.add(commonPath); String rel1 = getRelativePath(path1, commonPath); String rel2 = getRelativePath(path2, commonPath); if (!rel1.isEmpty()) { result.add(rel1); } if (!rel2.isEmpty()) { result.add(rel2); } return result; }