aspose file tools
The moose likes Beginning Java and the fly likes how to access a bean in an arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "how to access a bean in an arraylist" Watch "how to access a bean in an arraylist" New topic
Author

how to access a bean in an arraylist

J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 380
    
    3

This is part of a servlet/JSP app, but I've simplified the problem down to a simple test case and posted it here as a core Java problem.

I have an ArrayList of beans. How do I access the properties of those beans?


The error is "array required, but java.util.List<SimpleBean> found". That's not very helpful. Array required where? I'm reading from an array element. I want the bean and it's properties, not another array.

I know the answer is going to be a forehead-slapper, but I've struggled with this long enough. Can someone please point out the obvious answer for me?

Thanks


"I have a mind like a steel... uh... thingy."
Billy Nicholson
Greenhorn

Joined: Jun 16, 2011
Posts: 8
You're accessing an ArrayList as if it were an array.
Try: myList.get(0) to retrieve the bean.
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 380
    
    3

Doh! Told you it was going to be a forehead-slapper. Both of these work:



Thanks for the help.
Billy Nicholson
Greenhorn

Joined: Jun 16, 2011
Posts: 8
No worries!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how to access a bean in an arraylist
 
Similar Threads
Problem adding in ArrayList
BeanBox problems
how to pass the values and how to get the Arraylist table from java script function
How to extract and print the contents of arraylist of java bean objects?
Struts-Nested tags : Problem using checkbox check all and uncheck all