Methods Summary |
---|
public static void | main(java.lang.String[] args)
byte[] b = new byte[15];
r.nextBytes(b); // Fill with random bytes
print(b);
Arrays.sort(b);
print(b);
int loc = Arrays.binarySearch(b, b[10]);
System.out.println("Location of " + b[10] +
" = " + loc);
// Test String sort & search:
String[] s = randStrings(4, 10);
print(s);
Arrays.sort(s);
print(s);
loc = Arrays.binarySearch(s, s[4]);
System.out.println("Location of " + s[4] +
" = " + loc);
|
public static void | print(byte[] b)
for(int i = 0; i < b.length; i++)
System.out.print(b[i] + " ");
System.out.println();
|
public static void | print(java.lang.String[] s)
for(int i = 0; i < s.length; i++)
System.out.print(s[i] + " ");
System.out.println();
|
public static java.lang.String | randString(int length)
// Create a random String
char[] buf = new char[length];
int rnd;
for(int i = 0; i < length; i++) {
rnd = Math.abs(r.nextInt()) % src.length;
buf[i] = src[rnd];
}
return new String(buf);
|
public static java.lang.String[] | randStrings(int length, int size)
String[] s = new String[size];
for(int i = 0; i < size; i++)
s[i] = randString(length);
return s;
|