aspose file tools*
The moose likes Beginning Java and the fly likes ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayList" Watch "ArrayList" New topic
Author

ArrayList

Rajat Sarkar
Greenhorn

Joined: Sep 07, 2008
Posts: 18
ArrayList list =new ArrayList(); & ArrayList<Object> list = new ArrayList<Object>();
is both statement works same?is there any difference between them?
Balagopal Kannampallil
Ranch Hand

Joined: Oct 18, 2004
Posts: 136

You can add objects to both the lists. Only place where it breaks is when you assign any other type safe ArrayList to ArrayList<Object>. Something like this


SCJP 5.0 and now fighting with ExtJS
Marky Vasconcellos
Ranch Hand

Joined: Jan 28, 2009
Posts: 36
The difference was.. the compiler will claim you about he doens't know the type of objects will be in the first List.
anyway.. he assigns Object as Type but in the second case at least he know you provided this information.^^


Each of their nuggets of wisdom contracted to a sound bite: Joshua Bloch: Write Lots of Code; Chet Haase: Don't Put Your Entire Application in One Method; Masood Mortazavi: Start Simple and Keep Learning; Cay Horstmann: First, Don't Panic
 
Consider Paul's rocket mass heater.
 
subject: ArrayList
 
Similar Threads
Generics
Generics Question:
Problem with arraylist
GENERICS
Three Dimensional ArrayList?