Skip to content
Java List and ArrayList
Profile icon
ShadeVI

Hi guys,
is there any difference between these two ways?

List wordlist = new ArrayList <> ();

and

ArrayList wordlist = new ArrayList ();

You are viewing a single comment. View All
Answered by hellooneplus [earned 5 cycles]
View Answer
Profile icon
RYANTADIPARTHI

Solution

the list in java is not dynamic, Meaning it can hold only a certain amount on information, based on what you put. So whatever value you want it to hold, that's all it can. While the array list is a dynamic. You don't have to specify anything. You can add how much you want. the internal process just makes more, and more space foryou to add unlimited.

Profile icon
ShadeVI

@RYANTADIPARTHI
thanks, but in the first example i still don't understand why the declaration type is List and the implementation is ArrayList<>. This is a list or an arrayList?

Profile icon
RYANTADIPARTHI

@ShadeVI
well it's just like that. they have differences. this is a arraylist btw. What you are showing is an arraylist.

Profile icon
Coder100

no, you're wrong, arrays have stsatic length, but list and arraylist have dynamic length

@RYANTADIPARTHI