• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

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

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use the generic type Object (e.g. ArrayList<Object>) that's also possible.
 
Bartender
Posts: 2910
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why do you want to store different objects in the same list??
 
Rob Spoor
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

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

Thanks!
Sumanta
 
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sumanta:

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

John.
reply
    Bookmark Topic Watch Topic
  • New Topic