Guava’s Ints.asList() returns a fixed-size list backed by the specified array.
Syntax:
public static List<Integer>
asList(int[] array)
Parameters: This method takes the array as parameter which is the array to back the list.
Return Value: This method returns a fixed-size list backed by the specified array.
Example 1:
import com.google.common.primitives.Ints;
import java.util.List;
class GFG {
public static void main(String[] args)
{
int arr[] = { 1 , 2 , 3 , 4 , 5 };
List<Integer> myList = Ints.asList(arr);
System.out.println( "List of given array: "
+ myList);
}
}
|
Output:
List of given array: [1, 2, 3, 4, 5]
Example 2:
import com.google.common.primitives.Ints;
import java.util.List;
class GFG {
public static void main(String[] args)
{
int arr[] = { 3 , 5 , 7 };
List<Integer> myList = Ints.asList(arr);
System.out.println( "List of given array: "
+ myList);
}
}
|
Output:
List of given array: [3, 5, 7]
Reference: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/primitives/Ints.html#asList-int…-