Tech Novice
asked on
what is difference between list and arraylist
Hi,
List lst = new ArrayList();
What is the use of programming to interface,its just that in future we need to change from arraylist to another collection which i think we never come across such scenario then what's the use of?
List lst = new ArrayList();
What is the use of programming to interface,its just that in future we need to change from arraylist to another collection which i think we never come across such scenario then what's the use of?
ArrayList is the implementation, List is the interface.
What is the use of programming to interface,its just that in future we need to change from arraylist to another collection which i think we never come across such scenario then what's the use of?For List it's extremely rare since people almost always just use ArrayList.
But you may see the value more from Map:
Map<String, String> map = new HashMap<String, String>() ;
Map<String, String> map = new TreeMap<String, String>() ;
Map<String, String> map = new ConcurrentHashMap<String, String>() ;
are all found frequently in production code and being able to switch from one to the other without changing everything that uses "map" is a big saving.Doug
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Does it mean that if i go with
List lst = new ArrayList();
then i can access all the methods of list classs only i.e if there is method say method1 which is in arrayist and not part of list i will not be able to use it right?
How would you add a method to ArrayList?
ASKER
Not talking about adding method,just for sake of example i said if there is a method say method1(ensureCapacity) which is in arrayist and not part of list i will not be able to use it right?
Given what I said in my comment before last, added to what you already seem to know about interfaces and classes, maybe you can now answer that.