SHARE
TWEET

OptionalInt

DulcetAirman Aug 28th, 2018 (edited) 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   public static OptionalInt max1(int... a) {
  2.     return Arrays.stream(a).max();
  3.   }
  4.  
  5.   public static OptionalInt max2(int... a) {
  6.     if (a == null || 0 == a.length)
  7.       return OptionalInt.empty();
  8.     int max = a[0];
  9.     for (int i = 1; i < a.length; i++) {
  10.       if (a[i] > max)
  11.         max = a[i];
  12.     }
  13.     return OptionalInt.of(max);
  14.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top