Java examples for java.lang:int
Returns the smaller of the two Integers.
/*// www. j a v a2s. com * Copyright (c) 2015-2016 QuartzDesk.com. * Licensed under the MIT license (https://opensource.org/licenses/MIT). */ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { Integer i1 = 2; Integer i2 = 2; System.out.println(min(i1, i2)); } /** * Returns the smaller of the two Integers. A null Integer * is treated as smaller then {@link Integer#MIN_VALUE}. * * @param i1 the first Integer. * @param i2 the second Integer. * @return the smaller of the two Integers. */ public static Integer min(Integer i1, Integer i2) { if (i1 != null && i2 != null) return min(i1.intValue(), i2.intValue()); return null; } /** * Returns the smaller value of the two int arguments. * * @param i1 the first int. * @param i2 the second int. * @return the smaller value of the two int arguments. */ public static int min(int i1, int i2) { return i1 < i2 ? i1 : i2; } /** * Returns the smaller of the two Doubles. A null Double * is treated as smaller then {@link Double#MIN_VALUE}. * * @param d1 the first Double. * @param d2 the second Double. * @return the smaller of the two Doubles. */ public static Double min(Double d1, Double d2) { if (d1 != null && d2 != null) return min(d1.doubleValue(), d2.doubleValue()); return null; } /** * Returns the smaller value of the two double arguments. * * @param d1 the first double. * @param d2 the second double. * @return the smaller value of the two double arguments. */ public static double min(double d1, double d2) { return d1 < d2 ? d1 : d2; } }