What is the difference between these two declarations?
Declaration 1:
ArrayList<String> arrayList = new ArrayList<String>();
Declaration 2:
List<String> arrayList = new ArrayList<String>();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Is generic where you want to hide implementation details while returning it to client, at later point of time you may change implementation from
ArrayListtoLinkedListtransparently.This mechanism is useful in cases where you design libraries etc., which may change their implementation details at some point of time with minimal changes on client side.
This mandates you always need to return
ArrayList. At some point of time if you would like to change implementation details toLinkedList, there should be changes on client side also to useLinkedListinstead ofArrayList.