RosettaCodeData/Task/Search-a-list/Java/search-a-list-2.java

12 lines
373 B
Java
Raw Permalink Normal View History

2015-11-18 06:14:39 +00:00
import java.util.Arrays;
String[] haystack = { "Zig","Zag","Wally","Ronald","Bush","Krusty","Charlie","Bush","Bozo"};
2013-04-10 12:38:42 -07:00
for (String needle : new String[]{"Washington","Bush"}) {
2015-11-18 06:14:39 +00:00
int index = Arrays.binarySearch(haystack, needle);
if (index < 0)
System.out.println(needle + " is not in haystack");
else
System.out.println(index + " " + needle);
2013-04-10 12:38:42 -07:00
}