This is a general question as to what kind of list needs to be used to accumulate data while looping through a JDBC ResultSet object.
I work for a project where certain queries return thousands of records. SQL queries are executed using JDBC methods and the resultant values are looped through a ResultSet. The SQL query produces a sorted order.
List<Company> list = new ArrayList<>();
ResultSet rs = statement.execute();
while (rs.next()){
Company company = new Company();
rs.getString("company_name");
rs.getInteger("company_id");
list.add(company);
}
This list is returned to the service layer and data binding is done through JAXB or Jackson ObjectMapper to convert it to an XML format or a JSON object and returned as a part of REST call.
There are ~200 such code snippets where an ArrayList is used to accumulate the resultant data.
Query: Since the list is getting structurally modified with every addition of a new data item, will using a LinkedList instead of ArrayList make any difference? Which one of it can be used to improve the performance?
Note that the list is not manipulated else where in the application. Data is inserted in the data layer and is transformed in the service layer.