• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Iterating through a collection that contains user defined objects

 
Greenhorn
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15529
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15529
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, and welcome to CodeRanch, Divya!
 
Master Rancher
Posts: 4830
74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tips everyone
JavaRanch is great! I am not sure why I didn't sign up earlier!
 
Do you want ants? Because that's how you get ants. And a tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic