I am fairly new to the concept of arraylists. I have some data in two arraylist of type String[]. I want to compare them and store them in a new ArrayList<String[]>.
following is my code:
ArrayList<String[]> org = arr2;
ArrayList<String[]> text = arr3;
ArrayList<String[]> outList = new ArrayList<>() ;
System.out.println();
for(int i = 0; i < org.size(); i++) {
for(int x = 0; x < org.get(i).length; x++) {
System.out.printf("OrgId[%d][%d]: ", i, x);
System.out.println(orgId.get(i)[x]);
}
}
System.out.println();
for(int i = 0; i < text.size(); i++) {
for(int x = 0; x < text.get(i).length; x++) {
System.out.printf("file[%d][%d]: ", i, x);
System.out.println(text.get(i)[x]);
}
}
the values for org and text are as follows:
org: {student1,student2,student3}
text: {student3,student4,student1,student5}
both arraylists are of different sizes.
I want to use an if statement or some logic that can results in the results as:
outList: {student1,student3}
i.e.I want to add only the values which are present in both the lists, into a new list. Something like this:
Anonymous User
22-Apr-2015