I agree with Gopi, with a few more comments. For the person writing the method, ArrayList will usually be easier to program with. For a person who wants to use the method, it may be slightly clearer if the method returns an array. E.g.
tells another programmer instantly that the things in the array are Maps, and if they try to use them as some other incompatible object, the compiler will yell at them. But
does not do this. I need to include a javadoc comment here saying that the things in the List are all Maps. And there's no guarantee that other programmers will actually read the javadoc. (Of course if they don't, it's their own fault when ClassCastException is thrown.) So it may be useful to return an array here - even if most of the work inside the method was done with an ArrayList. You can just convert at the end of the method:
Of course there's a slight performance hit to copy the List contents into the array, but in most cases it's not a big deal, and the extra ease-of-use may be worth it. May have other benefits too, like if you don't want other classes to be able to access your private List - you can just give them a copy. Changes to the array don't affect the List. (Though changes to the objects in the array certainly affect the objects in the List; they're the same objects after all.) I was more likely to return an array than a List back when collections were new to the language, and I couldn't be sure that other programmers would know how to use them effectively. Nowadays I'm more likely to say to heck with them if they don't understand it; they need to learn collections. But it depends on my mood. [ January 31, 2003: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: What better: return Hashtable or List of Hashtables?