Saturday, November 22, 2025
HomeLanguagesJavaInts asList() function | Guava | Java

Ints asList() function | Guava | Java

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:




// 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);
    }
}


Output:

List of given array: [1, 2, 3, 4, 5]

Example 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);
    }
}


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…-

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6785 POSTS0 COMMENTS
Nicole Veronica
11932 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12000 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6864 POSTS0 COMMENTS
Umr Jansen
6851 POSTS0 COMMENTS