Guava 的Ints.asList()返回指定數組支持的固定大小的列表。
用法:
public static List<Integer> 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<Integer> 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<Integer> myList = Ints.asList(arr);
// Displaying the elements in List
System.out.println("List of given array:"
+ myList);
}
}
輸出:
List of given array:[3, 5, 7]
相關用法
- Java Guava Ints min()用法及代碼示例
- Java Guava Ints contains()用法及代碼示例
- Java Guava Ints max()用法及代碼示例
- Java Guava Ints indexOf()用法及代碼示例
- Java Guava Ints toArray()用法及代碼示例
- Java Guava Ints join()用法及代碼示例
- Java Guava Ints lastIndexOf()用法及代碼示例
- Java Guava Ints concat()用法及代碼示例
- Java Guava Bytes.asList()用法及代碼示例
- Java Guava Shorts.asList()用法及代碼示例
- Java Guava Booleans.asList()用法及代碼示例
- Java Guava Chars.asList()用法及代碼示例
- Java Guava Doubles.asList()用法及代碼示例
- Java Guava Floats.asList()用法及代碼示例
- Java Guava Longs.asList()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 Ints asList() function | Guava | Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。