• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to store multiple object(like Integer and String) in a Arraylist and Getting the data  RSS feed

 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

In the Arraylist how to store multiple object(like Integer and String) in a Arraylist and passing the same obj in a method to getting the data.

Please suggest.

Thanks and Regards,
Sumanta
 
Joybrata Chakraborty
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sumanta panda wrote:Dear All,

In the Arraylist how to store multiple object(like Integer and String) in a Arraylist and passing the same obj in a method to getting the data.

Please suggest.

Thanks and Regards,
Sumanta


If you don't use generics, you can add any objects in ArrayList.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use the generic type Object (e.g. ArrayList<Object>) that's also possible.
 
salvin francis
Bartender
Posts: 1653
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:If you use the generic type Object (e.g. ArrayList<Object>) that's also possible.

possible, yes, but is it advisible ?
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do you want to store different objects in the same list??
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:
Rob Prime wrote:If you use the generic type Object (e.g. ArrayList<Object>) that's also possible.

possible, yes, but is it advisible ?

If you need a mixed-type collection you have little choice.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In practice you rarely need a mixed-type collection, and if you do, you should have a good look at the design of your application. To me, the need for a mixed-type collection sounds like a code smell. If you use such a collection, then somewhere in your code you're going to use ugly things like casts or the instanceof operator.
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Could you please suggest me how we write the piece of code for the needful?

Thanks!
Sumanta
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sumanta:

You might want to consider creating a new, purpose-built class for this problem.

John.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!