• Post Reply Bookmark Topic Watch Topic
  • New Topic

Iterating through a collection that contains user defined objects  RSS feed

 
Greenhorn
Posts: 21
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to know if there is any way in which I could iterate through an arraylist/ any collection that contains user defined objects.
All the examples I have seen so far show me how I can add strings to a collection and print them out. But that's not exactly what I have in mind.
I am working on implementing the following functionality:

There is a method that essentially adds some user-defined objects, that contain some user info, to a collection. This collection is then passed to another method that reads the content of the objects it has received, fetches one of the values in the object: email address and then calls the sendEmail function that is already in place.

I need to figure out how I can parse the content of the objects and retrieve specific data from them.

Any help would be appreciated!

Thanks a lot!

Cheers,
Divya
 
Saloon Keeper
Posts: 7994
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's stopping you from replacing the Strings in the examples you saw, with your user defined class?
 
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are also several methods in the ArrayList and Collection APIs that can retrieve objects from an ArrayList/Collection


Hunter
 
Stephan van Hulst
Saloon Keeper
Posts: 7994
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and welcome to CodeRanch, Divya!
 
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing magically different about user-defined classes compared to other classes. A HashMap or ArrayList doesn't know the difference, or care.
 
Divya Chandrasekhar
Greenhorn
Posts: 21
Chrome Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips everyone
JavaRanch is great! I am not sure why I didn't sign up earlier!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!