I have a java String array which contains values like below :
arr[0] = "ClassA -> ClassSuper";
arr[1] = "ClassSuperSuper -> ClassSuperSuperSuper";
arr[2] = "ClassC -> Java/lang/object";
arr[3] = "ClassSuper -> ClassSuperSuper";
If the array is like above, I want to format this array into a form which reflects the relationship between the values of the above array. Relationship in the sense, for each class; super classes of that class should be appended to theright.
As an example i want to format the above array as follows :
arr[0] = "ClassA -> ClassSuper-> ClassSuperSuper -> ClassSuperSuperSuper";
arr[1] = "ClassSuperSuper -> ClassSuperSuperSuper";
arr[2] = "ClassC -> Java/lang/object";
arr[3] = "ClassSuper -> ClassSuperSuper -> ClassSuperSuper";
Please help me on this. I'm a newbie to java an spent hours on this but still couldn't succeed. This is what I have done till now.
for(int t=0; t<superOrInterfaceList.length;t++) {
if(superOrInterfaceList[t] != null) {
String co = superOrInterfaceList[t].substring((superOrInterfaceList[t].lastIndexOf('>')+1),superOrInterfaceList[t].length());
for(int s=0; s<superOrInterfaceList.length;s++) {
if(superOrInterfaceList[s] != null) {
String cof = superOrInterfaceList[s].substring(0,(superOrInterfaceList[s].indexOf('-')));
if(cof.equals(co)) {
superOrInterfaceList[t] = superOrInterfaceList[t]+"->"+cof;
}
}
}
}
}
But I'm getting some weird kind of values in my array after executing this loop. It does find a super class only for 1 level and then repeatedly append it again and again. I'm getting answers like bellow when I print the array after running the above code.
"ClassA-> ClassSuper -> ClassSuper -> ClassSuper ..."
Please help me to correct my code. Or if you have another good way please let me know. If you need any more clarifications to answer this please ask.