InterviewSolution
| 1. |
Which Is The Preferred Collection Class To Use For Storing Database Result Sets? |
|
Answer» When retrieving database RESULTS, the best collection IMPLEMENTATION to use is the LinkedList. The benefits include:
ResultSet result = stmt.executeQuery("..."); List list = new LinkedList(); while(result.next()) { list.add(result.getString("col")); } If there are multiple columns in the result set, you'll have to combine them into their own data structure for each row. ARRAYS work well for that as you know the size, though a custom class might be best so you can convert the contents to the proper type when extracting from databse, instead of later. When retrieving database results, the best collection implementation to use is the LinkedList. The benefits include: If there are multiple columns in the result set, you'll have to combine them into their own data structure for each row. Arrays work well for that as you know the size, though a custom class might be best so you can convert the contents to the proper type when extracting from databse, instead of later. |
|