This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Retrieving JavaBean properties from a list of beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Retrieving JavaBean properties from a list of beans" Watch "Retrieving JavaBean properties from a list of beans" New topic

Retrieving JavaBean properties from a list of beans

Anshul Chandra Saxena

Joined: Sep 10, 2009
Posts: 14

I have a list of beans. I now want to retrieve the properties from the bean and then compare the properties. Can anyone please help me in this .

public class WireBean {

private String sourceName;
private String targetName;

public String getSourceName() {
return sourceName;

public void setSourceName(String sourceName) {
this.sourceName = sourceName;

public String getTargetName() {
return targetName;

public void setTargetName(String targetName) {
this.targetName = targetName;

Based on the different values set in the properties, i have put the bean in a list. (list.add(wireBean))

Now i want to iterate through this list and i want to check the properties of sourceName in different beans and if they are equal, i want to put them in a Map.

Can anyone , please help !

Ketan Parikh

Joined: May 24, 2006
Posts: 6

You may use the get(int index) method available in List.

for(int i=0; i<beanList.size(); i++)

WireBean firstBean = (WireBean)beanList.get(i);

for(int j=i+1; j><=beanList.size(); j++)

WireBean secondBean = (WireBean)beanList.get(j);

if(hasSameSourceName()) //I think you may write this method easily; OR you may use comparable interface and have compareTo method

putInToMap(); //You may write this method. I don't know, what exactly you want to put in your map




Let me know, if this helps you
Rob Spoor

Joined: Oct 27, 2005
Posts: 19655

Welcome to both of you. Could you please Use Code Tags in the future?

How To Ask Questions How To Answer Questions
It is sorta covered in the JavaRanch Style Guide.
subject: Retrieving JavaBean properties from a list of beans
Similar Threads
Struts 1.x : stuck with html:select
Swing JCombobox and JTable issue
Why ModelDriven not working?
HFSJ Question in JSTL
How to create the clickable list