Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
actually i know how to find indexof ({1,3,5,7,9},3) that is int array but i am little bit confused about how to find indexof ({"1","3","5","7","9"},"3") that is string array
i want to do this by using binary search i need guidelines thank you.
Posted

1 solution

They are both a like. Just their data types are different. One turn around would be, to conver the string values to integer values on the run time. Like this

C#
Convert.ToInt16(element);


.. and then run the same process on it.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Nov-14 16:17pm    
The first part of the answer is correct, and the whole answer may work, depending on what's needed. But this is a very specialized solution. It won't work, for example, in the simple case when the string "032" and "32" are considered as different elements. Moreover, "binary search" (I hope, OP means the search based on dichotomy by that) only makes sense if the list is ordered. The really comprehensive answer would be using Java generics; the method should accept an element type as a generic parameter, and a comparison function using this type as one of the method arguments.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900