File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Always when I use List is for return any data from Data Base, right? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Always when I use List is for return any data from Data Base, right?" Watch "Always when I use List is for return any data from Data Base, right?" New topic
Author

Always when I use List is for return any data from Data Base, right?

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
Always when I use List is for return any data from Data Base, right?

And why I need many people use ArrayList together?

Look at:


Can I list using many other ways, right? I just heard about that this way of use
as a typed way... is it correct?

bye,
André AS
São Paulo - Brazil
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

you are right. always use Interface to a Type assignment. so that you wont dependent[tiedup] to a particular implementation of the List. i.e, later you want to change to LinkedList implementation, then only List<Name> names new = ArrayList<Name>(); will change to List<Name> names new = LinkedList<Name>();

hth
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

André Asantos wrote:Always when I use List is for return any data from Data Base, right?


It depends on your situation
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
thank you...

André AS
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

André Asantos wrote:Always when I use List is for return any data from Data Base, right?

Depends on if you're getting more than one--that kind of detail should be handled in a lower layer than the client code. For example, if I want to select a user by id I wouldn't want a list back, I'd want a user. But if I wanted all users whose first name starts with "A" I'd want a list, even if there might be none or only one.
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

André Asantos wrote:thank you...

you are welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Always when I use List is for return any data from Data Base, right?
 
Similar Threads
Use ArrayList in ActionForm
When should interfaces be used?
Proper use of generics??
@ManytoMany with join table and @CollectionOfElements : conceptual difference
<identifier> expected