Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList

 
Rajat Sarkar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marky Vasconcellos
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.^^
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic