Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList

 
renu richard
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
is there something like this
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the declaration of an ArrayList looks something like that.

Justin
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Renu,

I think what you're asking is whether you can use a primitive like "int" as a generic type parameter to a class. The answer is no, you can't; Java doesn't support that.
 
Balagopal Kannampallil
Ranch Hand
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

One can only use reference types as the Type argument while using generics. You can make your own generic classes but cannot use primitives as Type arguments. You can use their wrappers as Type arguments and put the primitives directly into the ArrayList with the help of autoboxing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic