I have input as:
String[] a = {"1.0.0","13.2.4","1.0.1","0.0.0","2.3.4","1.1.2","12.2.2","12.2.1"};
I want the output as:
{0.0.0, 1.0.0, 1.0.1, 1.1.2, 2.3.4, 12.2.1, 12.2.2, 13.2.4};
I'm stuck where I can't find a way to compare two elements. My code just compare once instead of comparing all the elements:
public static String[] compare(String[] a) {
String temp;
String[] a1;
String[] a2;
for (int i = 0; i < a.length - 1; i++) {
a1 = a[i].split("\\.");
a2 = a[i + 1].split("\\.");
for (int j = 0; j < a1.length; j++) {
int v1 = j < a1.length ? Integer.parseInt(a1[j]) : 0;
int v2 = j < a2.length ? Integer.parseInt(a2[j]) : 0;
if (v1 > v2) {
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
j = a1.length;
} else if (v1 == v2) {
continue;
} else {
j = a1.length;
}
}
}
return a;
}