I am new to Java.
I want to know the difference between:
List< String > list = new ArrayList<>();
and
ArrayList< String > list = new ArrayList<String>();
and
ArrayList< String > list = new ArrayList<>();
Thanks
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.
The first one is only valid since Java 7, and is the equivalent of
It’s just less verbose.
Same for the third one, which is equivalent to
and thus strictly equivalent to the second one.
You should prefer the first one, for the reasons mentioned in the answers to the following question: List versus ArrayList as reference type?