Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2005

Tip: Looking for answers? Try searching our database.

Arrays.binarySearch(Object[], keyValue) and Reflection API

Thread view: 
Stalin - 29 Sep 2005 17:22 GMT
Hi guys,
public Objectbinary(Object[], String keyName, String keyValue){

????????
int index = binarySearch(Object[],????);
return Object[index];
}
To make this method work I have to give it array and object that it will be
looking for. The thing is I don't know what kind of object in Object [] so I
have construct it during runtime by only have keyName (Ex. "LastName" ) and
keyValue (Ex "Robinson").

I've been deeging Reflection API last couple of days but can't figure this
one out.

Anybody have an idea how to do it?

Thanks
Roedy Green - 29 Sep 2005 23:48 GMT
>To make this method work I have to give it array and object that it will be
>looking for. The thing is I don't know what kind of object in Object [] so I
[quoted text clipped - 5 lines]
>
>Anybody have an idea how to do it?

I suspect you may not need reflection at all.

All you need as a class called KV with two String fields key and
value.  You would implement a hashCode and equals method. See
http://mindprod.com/jgloss/hashmap.html

You then can say  

map .add ( "LastName",  new KV( "LastName", "Robinson" ) )

Or maybe you don't even need that just use String as both key and
value.

HashMap<String,String> map = new HashMap<String,String>( 149 );

map.put ( "LastName", "Robinson" );

String value = map.get( "LastName");
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.