jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Turn an object reference into useful data? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Turn an object reference into useful data?" Watch "Turn an object reference into useful data?" New topic
Author

Turn an object reference into useful data?

Jacob Morehouse
Greenhorn

Joined: Feb 22, 2012
Posts: 17
Hello!


This is probably an easy one, but for some reason my searches turn up nothing. I'm possibly Googling this wrong? Anywho, here's my code:


This results in references to those objects, like "passwordgeneratorfx.Password@41b192cc." I've given the Password class a method of "getPaswordContents" that returns a string value, but I cannot seem to reference it here. How would I call that method here on each object in the list?

Thanks,
Jake
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2628
    
    9

Jacob Morehouse wrote:Hello!


This is probably an easy one, but for some reason my searches turn up nothing. I'm possibly Googling this wrong? Anywho, here's my code:


This results in references to those objects, like "passwordgeneratorfx.Password@41b192cc." I've given the Password class a method of "getPaswordContents" that returns a string value, but I cannot seem to reference it here. How would I call that method here on each object in the list?

Thanks,
Jake


Hello Jake

Have you consider using the for-each loop?



If you get the "passwordgeneratorfx.Password@41b192cc" then the object is referring to the internal "toString()" method. You can override the toString() method to give you what you want.

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Jacob Morehouse
Greenhorn

Joined: Feb 22, 2012
Posts: 17
Of course after giving up and posting, I solve it:


And away we go! Still getting used to generics. Also, welcoming any better or more concise solutions. There's always someone out there with a better way to skin the proverbial cat.

Thanks,
Jake
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Turn an object reference into useful data?