开发者

android Arrays.binarySearch issue

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>Debu开发者_如何学编程g</item> <item>Test</item> <item>Release</item> </string-array>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜