Avatar of PowerEdgeTech
PowerEdgeTech
Flag for United States of America asked on

Easy ArrayList Question

Easy question:

ArrayList<String> alist = new ArrayList<String>();
ArrayList<String> alist = new ArrayList<>();
ArrayList<String> alist = new ArrayList();

All of the above SEEM to work identically.  Is that indeed the case?  Netbeans indicates that the first one is "redundant" and is happy with the last two.  Which is most correct, or is there one that is considered just good programming practice?  Is there any circumstance where one would be required over another?
Java

Avatar of undefined
Last Comment
PowerEdgeTech

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
CEHJ

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
PowerEdgeTech

ASKER
Weird that Netbeans doesn't give me a warning on the last one then ... just says the same as the second one: "may split declaration into a declaration and assignment".  So in 1.7, is the <> just shorthand because specifying the type again is simply redundant, and that there is never a time that the <> type in the assignment would ever differ from the <> in the declaration?
CEHJ

So in 1.7, is the <> just shorthand because specifying the type again is simply redundant, and that there is never a time that the <> type in the assignment would ever differ from the <> in the declaration?
Yes that's right
PowerEdgeTech

ASKER
Thank you :)
Your help has saved me hundreds of hours of internet surfing.
fblack61