search - How to find a certain property from an object in Java -
so i'm making book class, each book has title, author, etc... want make method searches through properties of objects , finds query. example
public void titlesearch(string query) { find book query title }
i'm not sure duplicate didn't know search for.
thanks help. let me know if need more of code.
look @ jxpath library. jxpath can use xpath queries search graphs of objects.
consider example of searhing addressses zipcode=90210:
address address = (address)jxpathcontext.newcontext(vendor). getvalue("locations[address/zipcode='90210']/address");
this xpath expression equivalent following java code:
address address = null; collection locations = vendor.getlocations(); iterator = locations.iterator(); while (it.hasnext()){ location location = (location)it.next(); string zipcode = location.getaddress().getzipcode(); if (zipcode.equals("90210")){ address = location.getaddress(); break; } }
Comments
Post a Comment