📜  整数 asList()函数|番石榴 |Java

📅  最后修改于: 2022-05-13 01:55:51.995000             🧑  作者: Mango

整数 asList()函数|番石榴 |Java

Guava 的Ints.asList()返回由指定数组支持的固定大小的列表。

句法:

public static List 
    asList(int[] array)

参数:此方法将数组作为参数,该数组是支持列表的数组。

返回值:此方法返回由指定数组支持的固定大小的列表。

示例 1:

// Java code to show implementation of
// Guava's Ints.asList() method
  
import com.google.common.primitives.Ints;
import java.util.List;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Creating an integer array
        int arr[] = { 1, 2, 3, 4, 5 };
  
        // Using Ints.asList() method to wrap
        // the specified primitive Integer array
        // as a List of the Integer type
        List myList = Ints.asList(arr);
  
        // Displaying the elements in List
        System.out.println("List of given array: "
                           + myList);
    }
}
输出:
List of given array: [1, 2, 3, 4, 5]

示例 2:

// Java code to show implementation of
// Guava's Ints.asList() method
  
import com.google.common.primitives.Ints;
import java.util.List;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
        // Creating an integer array
        int arr[] = { 3, 5, 7 };
  
        // Using Ints.asList() method to wrap
        // the specified primitive Integer array
        // as a List of the Integer type
        List myList = Ints.asList(arr);
  
        // Displaying the elements in List
        System.out.println("List of given array: "
                           + myList);
    }
}
输出:
List of given array: [3, 5, 7]

参考: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/primitives/Ints.html#asList-int…-