List<List<String>> lists = new ArrayList();
//fileName is a list of files to iterate through and extract data from
for (int x=0; x<fileName.size(); x++) {
// CSV Reader object
CSVReader readFile = new CSVReader(new FileReader(fileName.get(x)));
String[] nextLine = readFile.readNext(); // Parses through first line with headers
/**
* Populates each array with appropriate data
*/
List<String> tempList = new ArrayList();
while ((nextLine = readFile.readNext()) != null) {
tempList.add(nextLine[0]);
}
readFile.close();
lists.add(tempList);
}
My question for this is that I thought array lists were passed by reference. When I run this, I'm basically creating a list of lists, which then is populated for each file I add in. I thought that as soon as this for loop is exited, the "tempList" data would be dereferenced and be open to change in the memory. However, in my tests, the data stays in through a series of calculations without any change. What is the reason for this?
I'm passing an arraylist created in a for loop to another list of lists. Why does this temp list not get thrown into garbage collection when exiting the for loop?