Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 indexOf on array
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xtreemboarder




PostPosted: Thu Jan 26, 2006 8:49 pm   Post subject: indexOf on array

how do you indexOf on arrays?

would it be like:

int num = array.indexOf ("hello");

???????????????????
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Thu Jan 26, 2006 9:04 pm   Post subject: (No subject)

Short Answer: You can't.

Long Answer: You can, but it's a little different.

First sort your array.
Java:
Arrays.sort(array);

Second use binarySearch.
Java:
int index = Arrays.binarySearch(array, "somevalue");
wtd




PostPosted: Thu Jan 26, 2006 9:09 pm   Post subject: (No subject)

Or you could use Arrays.asList to get a List and then call that list's indexOf method.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: