Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing a field within an element of an Arraylist

 
Marjorie Gyles
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10236
58
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic