2015-09-07 11:44:36 -06:00
|
|
|
// arrays/AlphabeticSearch.java
|
2021-01-31 15:42:31 -07:00
|
|
|
// (c)2021 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2016-11-21 12:37:57 -08:00
|
|
|
// Searching with a Comparator import
|
2015-06-15 17:47:35 -07:00
|
|
|
import java.util.*;
|
2015-11-11 20:20:04 -08:00
|
|
|
import onjava.*;
|
2016-01-25 18:05:55 -08:00
|
|
|
import static onjava.ArrayShow.*;
|
2015-06-15 17:47:35 -07:00
|
|
|
|
|
|
|
public class AlphabeticSearch {
|
|
|
|
public static void main(String[] args) {
|
2016-01-25 18:05:55 -08:00
|
|
|
String[] sa = new Rand.String().array(30);
|
2015-06-15 17:47:35 -07:00
|
|
|
Arrays.sort(sa, String.CASE_INSENSITIVE_ORDER);
|
2016-01-25 18:05:55 -08:00
|
|
|
show(sa);
|
2016-11-21 12:37:57 -08:00
|
|
|
int index = Arrays.binarySearch(sa,
|
|
|
|
sa[10], String.CASE_INSENSITIVE_ORDER);
|
2017-01-23 08:18:49 -08:00
|
|
|
System.out.println(
|
|
|
|
"Index: "+ index + "\n"+ sa[index]);
|
2015-06-15 17:47:35 -07:00
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|
|
|
|
/* Output:
|
2017-05-03 12:00:00 -06:00
|
|
|
[anmkkyh, bhmupju, btpenpc, cjwzmmr, cuxszgv, eloztdv,
|
|
|
|
ewcippc, ezdeklu, fcjpthl, fqmlgsh, gmeinne, hyoubzl,
|
|
|
|
jbvlgwc, jlxpqds, ljlbynx, mvducuj, qgekgly, skddcat,
|
|
|
|
taprwxz, uybypgp, vjsszkn, vniyapk, vqqakbm, vwodhcf,
|
|
|
|
ydpulcq, ygpoalk, yskvett, zehpfmm, zofmmvm, zrxmclh]
|
|
|
|
Index: 10
|
|
|
|
gmeinne
|
2015-09-07 11:44:36 -06:00
|
|
|
*/
|