Java Ints类
Ints 是原始类型int的一个实用类。它提供了与int基元有关的 静态实用方法 ,这些 方法 在Integer或Arrays中都没有找到。
声明 :
@GwtCompatible(emulated=true)public final class Intsextends Object
下表显示了Guava Ints类的字段摘要:

Ints类提供的一些方法有:

异常。
下表显示了Guava的Ints类提供的其他一些方法:

下面给出了一些例子,显示了Guava的Ints类的方法的实现:
例1 :
// Java code to show implementation// of Guava Ints.asList() method import com.google.common.primitives.Ints;import java.util.*; class GFG { // Driver method public static void main(String[] args) { int arr[] = { 5, 10, 15, 20, 25 }; // Using Ints.asList() method which wraps // the primitive integer array as List of // integer Type List<Integer> myList = Ints.asList(arr); // Displaying the elements System.out.println(myList); }}
输出:
[5, 10, 15, 20, 25]
例2 :
// Java code to show implementation// of Guava Ints.toArray() method import com.google.common.primitives.Ints;import java.util.*; class GFG { // Driver method public static void main(String[] args) { List<Integer> myList = Arrays.asList(5, 10, 15, 20, 25); // Using Ints.toArray() method which // converts a List of Integer to an // array of int int[] arr = Ints.toArray(myList); // Displaying the elements System.out.println(Arrays.toString(arr)); }}输出:
[5, 10, 15, 20, 25]
例3 :
// Java code to show implementation// of Guava Ints.concat() method import com.google.common.primitives.Ints;import java.util.*; class GFG { // Driver method public static void main(String[] args) { int[] arr1 = { 5, 10, 15 }; int[] arr2 = { 20, 25 }; // Using Ints.concat() method which // combines arrays from specified // arrays into a single array int[] arr = Ints.concat(arr1, arr2); // Displaying the elements System.out.println(Arrays.toString(arr)); }}输出:
[5, 10, 15, 20, 25]
例4 :
// Java code to show implementation// of Guava Ints.contains() method import com.google.common.primitives.Ints; class GFG { // Driver method public static void main(String[] args) { int[] arr = { 5, 10, 15, 20 }; // Using Ints.contains() method which // checks if element is present in array // or not System.out.println(Ints.contains(arr, 10)); System.out.println(Ints.contains(arr, 17)); }}产出 :
truefalse
例5 :
// Java code to show implementation// of Guava Ints.min() method import com.google.common.primitives.Ints; class GFG { // Driver method public static void main(String[] args) { int[] arr = { 5, 10, 15, 20 }; // Using Ints.min() method System.out.println(Ints.min(arr)); }}输出:
5
例6 :
// Java code to show implementation// of Guava Ints.max() method import com.google.common.primitives.Ints; class GFG { // Driver method public static void main(String[] args) { int[] arr = { 5, 10, 15, 20 }; // Using Ints.max() method System.out.println(Ints.max(arr)); }}输出:
20
