-3

Possible Duplicate:
Type List vs type ArrayList in Java

Hi I have been asked the following question in an interview:

Which of the following would you choose recommended when and where?

ArrayList<SomeType> a = new ArrayList<SomeType>(); or
List<SomeType> a = new ArrayList<SomeType>();

I dont know much difference if anyone knows kindly please help. Thanks in advance.

0

1 Answer 1

8

Second is better cause you can simply change underlying implementation from ArrayList to LinkedList (or to any proper implementation) by one line code change.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, unless you need to use any methods that are specific to ArrayList.
In summary, you should code deliberately. Use ArrayList because you are using ArrayList specific method(s) otherwise use the interface List.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.