• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Retrieving JavaBean properties from a list of beans

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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 !




}
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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
 
Sheriff
Posts: 22696
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to both of you. Could you please Use Code Tags in the future?
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic