asList()
Java Guava中Ints类的方法返回一个固定大小的列表,该列表由指定数组支持。语法如下-
public static List<Integer> asList(int[] arr)
在这里,arr是支持列表的数组。
让我们看一个示例来实现asList()
Ints类的方法-
import com.google.common.primitives.Ints; import java.util.List; class Demo { public static void main(String[] args) { int arr[] = { 20, 30, 40, 60, 80, 90, 120, 150 }; System.out.println("Array elements = "); for(int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } List<Integer> list = Ints.asList(arr); System.out.println("List = "+ list); } }
输出结果
Array = 20 30 40 60 80 90 120 150 List = [20, 30, 40, 60, 80, 90, 120, 150]