Guava的短褲類的Shorts.min()方法用於查找數組中存在的最小值。此方法返回的值是指定數組中的最小short值。
用法:
public static short min(short... array)
參數:此方法采用強製參數數組,該參數數組是短值的非空數組。
返回值:此方法返回一個短值,該值是指定數組中的最小值。
異常:如果array為空,則該方法引發IllegalArgumentException。
下麵的示例說明Shorts類的min()方法:
範例1:
// Java code to show implementation of
// Guava's Shorts.min() method
import com.google.common.primitives.Shorts;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating a short array
short[] arr = { 2, 4, 6, 10, 0, -5, 15 };
// Using Shorts.min() method to get the
// minimum value present in the array
System.out.println("Minimum Value is:"
+ Shorts.min(arr));
}
}
輸出:
Minimum Value is:-5
範例2:
// Java code to show implementation of
// Guava's Shorts.min() method
import com.google.common.primitives.Shorts;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating a short array
short[] arr = {};
try {
// Using Shorts.min() method to get the
// minimum value present in the array
// This should raise "IllegalArgumentException"
// as the array is empty
System.out.println("Minimum Value is:"
+ Shorts.min(arr));
}
catch (Exception e) {
System.out.println(e);
}
}
}
輸出:
java.lang.IllegalArgumentException
相關用法
- Java Guava Doubles.min()用法及代碼示例
- Java Guava Doubles.contains()用法及代碼示例
- Java Guava Floats.contains()用法及代碼示例
- Java Guava Bytes.contains()用法及代碼示例
- Java Guava Longs.contains()用法及代碼示例
- Java Guava Longs.min()用法及代碼示例
- Java Guava Chars.min()用法及代碼示例
- Java Guava Floats.min()用法及代碼示例
- Java Guava Longs.max()用法及代碼示例
- Java Guava Doubles.max()用法及代碼示例
- Java Guava Chars.max()用法及代碼示例
- Java Guava Floats.max()用法及代碼示例
- Java Guava Booleans.contains()用法及代碼示例
- Java Guava Shorts.contains()用法及代碼示例
- Java Guava Chars.contains()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 Java Guava | Shorts.min() method with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。