• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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
 
Bartender
Posts: 15743
368
  • 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
Bartender
Posts: 15743
368
  • 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!
 
Rancher
Posts: 5184
84
  • 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!
reply
    Bookmark Topic Watch Topic
  • New Topic