|
-
October 25th, 2006, 12:29 PM
#1
List Arraylist Question
Hi!
I've been wondering why you can define and what is the difference when you create next:
List <Car> cars=new ArrayList<Car> ;
OR
List cars=new Arraylist();
so these both works but whats the real difference and when it matters that you define
List and ArrayList with <Car> ie. <E> because you can use it without too.
Thanks!
-
October 25th, 2006, 12:38 PM
#2
Re: List Arraylist Question
Hi,
<Car> is a generic, and by using it you are telling the VM that all objects inside the List will be of type Car, so when you retrieve an object from the List you won't have to cast it to a Car object. If you didn't use the <Car> generic then you would have to cast objects to Car in order to use them since the list will only return objects of type Object.
Have a look HERE for a fuller explanation.
Hope this helps
Byron Tymvios
Please use [ CODE ] and [/ CODE ] tags when posting code! See THIS on how to use code tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|