Link to home
Start Free TrialLog in
Avatar of Tech Novice
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?
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

ArrayList is the implementation, List is the interface.
Avatar of dpearson
dpearson

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>() ;

Open in new window

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
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tech Novice

ASKER

Does it mean that if i go with
List lst = new ArrayList();

Open in new window

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?
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.