aspose file tools*
The moose likes Beginning Java and the fly likes accessing a field within an element of an Arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "accessing a field within an element of an Arraylist" Watch "accessing a field within an element of an Arraylist" New topic
Author

accessing a field within an element of an Arraylist

Marjorie Gyles
Ranch Hand

Joined: Nov 03, 2012
Posts: 42

I am trying to access one field in an arraylist element. It is an arraylist<PixFile> (named photos) consisting of elements containing the fields of
fileName, photographerName, fileType, and double fileSize. I am only trying to access the fileName field of each element and
I'm not sure how to go about doing that. I have tried the photos.get(0) for the first file name, but I'm getting the entire toString method
but I only want a list of fileNames. HOw does one access only one field of the element?



Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8223
    
  23

Marjorie Gyles wrote:HOw does one access only one field of the element?

get(n), exactly as you've done, but what that returns you is a PixFile object. So how do you get the filname from that?

Tip: try this:and it's a good general rule to follow: break problems down. And if you're still having problems: StopCoding.

HIH

Winston

PS: An alternative is to use the for-each loop style. Very useful - especially in your case.

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessing a field within an element of an Arraylist