Arrays.binarySearch找不到最后一个元素

时间:2017-10-28 01:46:29

标签: java

char[] charArray = new char[] {'h','e','l','l','o','a'};
System.out.println(Arrays.binarySearch(charArray,'a'));

为什么它给我结果为-1而不是5?

1 个答案:

答案 0 :(得分:2)

Arrays#binarySearch(char[], char)说(部分)在进行此调用之前,必须对数组进行排序(如sort(char[])方法)。如果未排序,则结果未定义。首先排序 # Virtual Hosts # <VirtualHost *:80> ServerName localhost ServerAlias localhost DocumentRoot "${INSTALL_DIR}/www" <Directory "${INSTALL_DIR}/www"> Options +Indexes +FollowSymLinks +MultiViews AllowOverride All require all granted </Directory> ErrorLog "logs/localhost-error.log" CustomLog "logs/localhost-access.log" common LogLevel debug </VirtualHost> # # <VirtualHost *:80> DocumentRoot "c:/wamp64/www/propokeruk" ServerName propokeruk <Directory "c:/wamp64/www/propokeruk"> Options +Indexes +Includes +FollowSymLinks +MultiViews AllowOverride All Require local </Directory> ErrorLog "c:/wamp64/logs/propokeruk-error.log" AccessLog "c:/wamp64/logs/propokeruk-access.log" common LogLevel debug </VirtualHost> # # <VirtualHost *:80> DocumentRoot "c:/wamp64/www/tester" ServerName tester <Directory "c:/wamp64/www/tester"> Options +Indexes +Includes +FollowSymLinks +MultiViews AllowOverride All Require local </Directory> ErrorLog "c:/wamp64/logs/tester-error.log" AccessLog "c:/wamp64/logs/tester-access.log" common LogLevel debug </VirtualHost> #。像,

charArray