• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList and Generics  RSS feed

 
Nirmit Dalal
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i came across this code

How do you interpret this ?
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resizable array that can hold references of class Integer.
 
Nirmit Dalal
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then saying
ArrayList<Integer> al =new ArrayList<Integer>(); is same
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try both variants in code and you will see the difference.
 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <> is called the diamond operator. You can read about it in the Java Tutorials, SO, JavaWorld and this Oracle page. Note you cannot use it in Java6 or before.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nirmit Dalal wrote:then saying
ArrayList<Integer> al =new ArrayList<Integer>(); is same

Basically: Yes. It's just an added feature in version 7 to save you from getting CTS so quickly.

Winston
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!