I am currently stuck while comparing two list of strings. Here are the inputs:
First list : three, two, ten, five.
Second list: three, ten, two, five.
The order is important in both list in such a way that: if one element index is not same in other list, then it should put an empty line.
I have attached a screen shot for better clarity.
Here is my code
public static void main(String[] args) {
List<String> list1 = new ArrayList<String>();
List<String> list2 = new ArrayList<String>();
list1.add("three");
list1.add("two");
list1.add("ten");
list1.add("five");
list2.add("three");
list2.add("ten");
list2.add("two");
list2.add("five");
for(int iIndex = 0, jIndex = 0; iIndex < list1.size() && jIndex < list2.size(); iIndex ++, jIndex++) {
if(!list1.get(iIndex).contentEquals(list2.get(jIndex))) {
list1.add(jIndex, "");
}
}
Note: I have searched and checked each listed topics before posting this question. Thank you for your help