1
String[] array =
     getContext().getResources().getStringArray(R.array.DevCategories);

to get an array. I the call this:

Arrays.binarySearch(array,"Plan"));

it returns -5, I am sure the first value of the array is Plan. What happend?

By the way, the current class is extended from ContentProvider. I am writing a Provider.

I use this code get -5

String.format("%d",Arrays.binarySearch(array,"Plan"))); String.valueOf(Arrays.binarySearch(array,"Plan")));

both are -5

R.array.DevCategories from string.xml file. <string-array name="DevCategories"> <item>Plan</item> <item>Design</item> <item>Coding</item> <item>Debug</item> <item>Test</item> <item>Release</item> </string-array>

1 Answer 1

1

Are you sure that the Array is sorted according to the natural sort order (for Strings in this case)?

Results are undefined if the Array is not sorted.

A negative result normally indicates that the key was not found and the result can be used to calculate the index at which the key should be inserted to add it to the Array (to maintain the proper sorting). This will be bogus if the Array was not sorted to begin with.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.