Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saqibmehmoodgit/9856e748f93f1839b505767281e21e96 to your computer and use it in GitHub Desktop.
Save saqibmehmoodgit/9856e748f93f1839b505767281e21e96 to your computer and use it in GitHub Desktop.
public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
int count = 0;
for (T e : anArray)
if (e.compareTo(elem) > 0)
++count;
return count;
}
//////////
Integer[] arr= new Integer[3];
arr[0]=5;
arr[1]=7;
arr[2]=9;
Integer elem = 6;
System.out.println(" total is " + GenericMethods.countGreaterThan(arr, elem));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment