-
Why ArrayList need List interface?
Why ArrayList need List interface?
-
My question is, In your opinion, why ArrayList should not use List Interface?
-
The following still workable right?
ArrayList list = new ArrayList();
-
Please be clear of your question. i am not able to understand what the question can you please explain it and what kind of answer are you expecting.
Thanks
-
My question is very easy. Why Sun expert develop List interface for ArrayList?
-
when you need a collection , there are some candidates.
( they differ in implementation )
each of them has some strong and weak points.
you make a decision depends on your problem
and choose one..
for details you can look at a data structures and algorithms book.
imagine this method:
ArrayList myMethod( ArrayList l ){
...
}
there may be a lot of methods in your code.
and if you change you decision after a time ?
( switch ArrayList to LinkedList )
but this way, no change required:
List myMethod( List l ){
...
}
-
See, interfaces are created for better software design and engineering. ArrayList is a type of List and so is LinkedList. List interface defines common methods that has to be implemented by a concrete List data strucuture.
Say your software requires to use Lists but there are many types of lists, doubly, array based etc. It might be possible that some implentation is specifically best for problem in hand. Also it might be possible that later on you come up with your own List implementation which is better than one provided by library(although chances for this are slim).
So in your code you can simply pass something like this
someFunction( List list )
and you can call someFuntion with any class object which implements List interface.
I doubt I have answered your question, but think advantage of having List interface from design point of view.
Regards,
Mohit
-
Mohit has explained it clearly but still if you don't understand Let me explain in a more better sense. More technical.
Suppose you want to write a program which takes input a list of numbers. When I meant list of numbers i mean many numbers which your program accepts and does some logic.
Please concentrate on the numbers you are passing. I said you accepting it as an input.
and so you are not the one who is going to call the method or the program.some other person, say XXX is going to call. XXX knows that he has to pass many numbers to your program, but does not know what your program does,But he know that the he has to pass many programs and he will required output.
Now how is he going to sent it.He can send it as a ArrayList,Array,or Linked List or Vector whatever it maybe,Your program should work.
And the second reason is to act as a proxy for the List Collections.
Hope by now you should have understoood it.Thanks
G.Rajasekhar
-
Similar Threads
-
By Gengar003 in forum Java
Replies: 10
Last Post: 05-15-2005, 06:14 AM
-
By Trey Hutcheson in forum .NET
Replies: 6
Last Post: 03-27-2002, 08:13 PM
-
By Larry Rebich in forum vb.announcements
Replies: 1
Last Post: 06-28-2001, 01:22 PM
-
By Vlad Ivanov in forum .NET
Replies: 0
Last Post: 12-15-2000, 02:58 PM
-
By Kevin Burton in forum .NET
Replies: 12
Last Post: 10-09-2000, 10:29 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|