If I understand your problem correctly, you're asking how to find the intersection of two lists while maintaining the reference to the equivalent data in a second list. You have a lot of information about the format of the file but you haven't asked any questions about reading the file so I'm going to assume you're ok with that. If not then I suggest you ask a separate question about reading files in your format.
Firstly, given each row in your files seems to represent a single record you should create a class to represent that record with the two 'columns' of data represented as instance variables. You will need methods to compare and print your records. I'm ignoring constructors etc.
class Record {
private final String value1;
private final String value2;
public boolean value1_Equals(Record other) {
return this.value1.equals(other.value1);
}
public void printTo(OutputStream out) {
...
}
}
Secondly, read your two files of data into two lists of records:
List<Record> records1;
List<Record> records2;
Thirdly, create a new list that is the intersection of those two. Here's an example using Java 8 streams; if you don't have Java 8 add a comment and I'll give an equivalent in Java 7 (though from your question it seems you know how to do this already):
List<Record> intersection = records1.stream()
.filter(record -> record2.stream().anyMatch(record::value1_Equals))
.collect(Collectors.toList());
Finally, print the intersection in a new list:
intersection.forEach(record -> record.printTo(file));
An equivalent version that does not use streams might be:
List<Record> intersection = new ArrayList(records1);
intersection.retainAll(records2);
for (Record record: intersection)
record.printTo(file);
'quotes?