While executing below code I'm getting:
(Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3)
Please, suggest what could be the changes that I have to do.
import java.util.ArrayList;
import java.util.List;
public class Testing {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
List < String > list1 = new ArrayList<String>();
list1.add("A");
list1.add("B");
list1.add("C");
List < String > list2 = new ArrayList<String>();
list2.add("A");
list2.add("D");
list2.add("E");
String str = null;
String Strcom1;
String Strcom2;
int maxLength = list1.size();
for (int i = 0; i <= list1.size(); i++) {
for (int j = 0; j < list2.size(); j++) {
Strcom1 = list1.get(i);
Strcom2 = list2.get(j);
//str=list1.get(1);
//System.out.println(str);
if (Strcom1.equals(Strcom2)) {
System.out.println("Matching found");
}
else {
System.out.println("No Matching found");
}
}
}
}