Skip to content

Instantly share code, notes, and snippets.

@edwardbeckett
Last active January 4, 2016 01:09
Show Gist options
  • Save edwardbeckett/149e2ce348cc8efb90e6 to your computer and use it in GitHub Desktop.
Save edwardbeckett/149e2ce348cc8efb90e6 to your computer and use it in GitHub Desktop.
Find second largest value in an int[]...
import java.util.Arrays;
import java.util.Random;
/**
* @author Edward Beckett <Edward@EdwardBeckett.com>
* @since 1/3/2016
*/
public class ArraySecondMax {
private static int[] nums = new Random().ints(10000, 0, 10000).toArray();
private static int secondMax (int... array) {
Arrays.stream(array).sorted().distinct();
return array.length-1;
}
public static void main(String[] args) {
System.out.println(secondMax(nums));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment