import java.util.Set; import java.util.HashSet; import java.util.Collection; import java.util.Comparator; public class Search { public static boolean search (int v, int[] data) { for (int x: data) if (x==v) return true; return false; } public static boolean search (int v, int[] data, int first, int n) { for (int i=first; i data) { // NB. Both x and v are of type 'int', not 'Integer'. for (int x: data) if (x==v) return true; return false; } public static boolean searchII (Integer v, Collection data) { // If numeric types, then auto-unboxing conversions apply to ==, // and the RHS is unboxed for (int x: data) if (x==v) return true; return false; } public static boolean searchIII (Integer v, Collection data) { // NB. Dangerous reference equality is used here! for (Integer x: data) if (x==v) return true; return false; } public static boolean gsearch (T v, Collection data) { for (T x: data) if (x.equals(v)) return true; return false; } // Pretty much forces T to implement Comparable public static boolean gsearchZ (Comparable v, Collection data) { for (T x: data) if (v.compareTo(x)==0) return true; return false; } // Subtype constraint; T must have a natural ordering public static > boolean gsearch (T v, Collection data) { for (T x: data) if (v.compareTo(x)==0) return true; return false; } // External means of comparision public static boolean gsearch (T v, Collection data, Comparator comp) { for (T x: data) if (comp.compare(x,v)==0) return true; return false; } public static void main (final String [] args) { final int [] data = new int [args.length]; final Set set = new HashSet<>(); final int v = Integer.parseInt (args[0]); int n = 0; for (int i=1; i