Guava Shorts类
Shorts是原始类型short的一个实用类。它提供了与短基元有关的静态实用方法,这些方法在Short或Arrays中都没有找到。
声明 :
@GwtCompatible(emulated=true)public final class Shortsextends Object
下表显示了Guava Shorts Class的字段总结。

Guava Shorts Class提供的一些方法有: 异常情况。


下表显示了Guava Shorts Class提供的一些其他方法:下面给出的一些例子显示了Guava Shorts Class方法的实现:例子1:
// Java code to show implementation// of Guava Shorts.asList() method import com.google.common.primitives.Shorts;import java.util.*; class GFG { // Driver method public static void main(String[] args) { short arr[] = { 3, 4, 5, 6, 7 }; // Using Shorts.asList() method which convert // array of primitives to array of objects List<Short> myList = Shorts.asList(arr); // Displaying the elements System.out.println(myList); }}
输出:
[3, 4, 5, 6, 7]
例2 :
// Java code to show implementation// of Guava Shorts.indexOf() method import com.google.common.primitives.Shorts;import java.util.*; class GFG { // Driver method public static void main(String[] args) { short[] arr = { 3, 4, 5, 6, 7 }; // Displaying the index for // first occurrence of given target System.out.println(Shorts.indexOf(arr, (short)5)); }}输出:
2
例3 :
// Java code to show implementation// of Guava Shorts.concat() method import com.google.common.primitives.Shorts;import java.util.*; class GFG { // Driver method public static void main(String[] args) { short[] arr1 = { 3, 4, 5 }; short[] arr2 = { 6, 7 }; // Using Shorts.concat() method which // combines arrays from specified // arrays into a single array short[] arr = Shorts.concat(arr1, arr2); // Displaying the elements System.out.println(Arrays.toString(arr)); }}输出:
[3, 4, 5, 6, 7]
例4 :
// Java code to show implementation// of Guava Shorts.contains() method import com.google.common.primitives.Shorts; class GFG { // Driver method public static void main(String[] args) { short[] arr = { 3, 4, 5, 6, 7 }; // Using Shorts.contains() method which // checks if element is present in array // or not System.out.println(Shorts.contains(arr, (short)8)); System.out.println(Shorts.contains(arr, (short)7)); }}输出:
falsetrue
例5 :
// Java code to show implementation// of Guava Shorts.min() method import com.google.common.primitives.Shorts; class GFG { // Driver method public static void main(String[] args) { short[] arr = { 3, 4, 5, 6, 7 }; // Using Shorts.min() method System.out.println(Shorts.min(arr)); }}输出:
3
例6 :
// Java code to show implementation// of Guava Shorts.max() method import com.google.common.primitives.Shorts; class GFG { // Driver method public static void main(String[] args) { short[] arr = { 3, 4, 5, 6, 7 }; // Using Shorts.max() method System.out.println(Shorts.max(arr)); }}输出:
7
