Collection vs array - thread safety

I am involved in a bug fix project and I am trying to retrieve using hibernate a number of records as mapped objects. Is there any issue with retrieving the objects in a collection. Everywhere they have used arrays to return rows from the hibernate layer

for example is there any advantage in using arrays. the application is a web app and multi threaded.

public Employees[] getEmployeesBySection(String code) {

return dao.getEmployeesBySection();///returns array

public Employees getEmployeesBySection(String code) {

return dao.getEmployeesBySection();//returns collection

I would prefer collection as it is easier for me to iterate but i would appreciate feedback if there is any reason to its usage in this particular project

[771 byte] By [cdpothena] at [2007-10-3 2:58:45]
# 1

If you are talked about hibernate, its return value is actually defined by yourself, no matter you return Collection like list set..... or array that would be fined.

Normally my practice also return in Collection value, meanwhile in your Dao layer, you should return the value of List, then should be easier for u to implement

Type safety issue it is not an concern,unless you said that you are returning an enum and you need it to be type safety,then you should return object list, else, you just return the collection should be fined. It is just depend on the developers.

Cheers......

ViQuEnYeEa at 2007-7-14 20:48:17 > top of Java-index,Core,Core APIs...
# 2

When you just want to iterate through list of objects, arrays shoud always be preferred over Collection.

Collection comes with loads of methods which are actually not required and hence should be avoided.

I know, with Java, efficiency is NOT that of the concern, but I personally do not like to use datastructure unless we are making use of traits of that particular datastructure.

think_in_javaa at 2007-7-14 20:48:17 > top of Java-index,Core,Core APIs...