List of utility methods to do Array Search
boolean | isInArray(String needle, String[] haystack) check to see if the given value is in the array return Arrays.asList(haystack).contains(needle);
|
int | memchr(boolean[] ary, int start, int len, boolean find) memchr for (int i = 0; i < len; i++) { if (ary[i + start] == find) return i + start; return -1; |
int | memchr(char[] haystack, int offset, char needle, int num) memchr if (num != 0) { int p = 0; do { if (haystack[offset + p] == needle) return 1; p++; } while (--num != 0); return 0; |
int | memchr(T[] ptr, T value) memchr for (int c = 0; c < ptr.length; c++) { if (value.equals(ptr[c])) return c; if (value.hashCode() == ptr[c].hashCode()) return c; return -1; |
String | replaceAll(String text, char[] toSearch, char toReplace) Replaces all occurrences of a search sign with the replacement sign. if (text != null && toSearch != null) { Arrays.sort(toSearch); char[] signs = text.toCharArray(); for (int i = 0; i < signs.length; i++) { int index = Arrays.binarySearch(toSearch, signs[i]); if (index >= 0) { signs[i] = toReplace; return new String(signs); } else { return text; |
int[] | search(double[] input, int[] bounds, double x) Recursive binary search. if (bounds[0] == bounds[1]) { return new int[] { bounds[0], bounds[1] }; if (bounds[1] - bounds[0] == 1) { return new int[] { bounds[0], bounds[1] }; if (input[bounds[0]] == x) { return new int[] { bounds[0], bounds[0] }; ... |
int | Search(int[] in, int val) Search return Search(in, val, true); |
int | searchFirst(String[] target, String key) search First if (isEmpty(target) || key == null) { return -1; for (int i = 0; i < target.length; i++) { if (key.equals(target[i])) { return i; return -1; |
boolean | searchInStringArray(String key, String[] data) search In String Array Set<String> values = new HashSet<String>(Arrays.asList(data)); return values.contains(key); |