Friday, June 19, 2026
HomeLanguagesJavaJava Guava | Doubles.asList() method with Examples

Java Guava | Doubles.asList() method with Examples

The Doubles.asList() method of Guava’s Doubles Class accepts a double array as a parameter and returns a list which has the fixed size. The returned list is backed by the double array which is passed as the argument. It means the changes made in the array passed as parameter will be reflected back in the list returned by the method and vice-versa.

Syntax:

public static List<Double> asList(double… backingArray)

Parameter: The method accepts a mandatory parameter backingArray which is a double array that is used to back the list.

Return Value: The method Doubles.asList() returns a fixed-size list which is backed by the array passed as the argument to the method. In other words, the method returns the list view of the array.

Below examples illustrate the implementation of above method:

Example 1:




// Java code to show implementation of
// Guava's Doubles.asList() method
  
import com.google.common.primitives.Doubles;
import java.util.List;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Creating a Double array
        double arr[] = { 1.2, 2.3, 3.4, 4.5, 5.6 };
  
        // Using Doubles.asList() method to wrap
        // the specified primitive Double array
        // as a List of the Double type
        List<Double> myList = Doubles.asList(arr);
  
        // Displaying the elements in List
        System.out.println(myList);
    }
}


Output:

[1.2, 2.3, 3.4, 4.5, 5.6]

Example 2:




// Java code to show implementation of
// Guava's Doubles.asList() method
  
import com.google.common.primitives.Doubles;
import java.util.List;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Creating a Double array
        double arr[] = { 3.2, 5.5, 7.6 };
  
        // Using Doubles.asList() method to wrap
        // the specified primitive Double array
        // as a List of the Double type
        List<Double> myList = Doubles.asList(arr);
  
        // Displaying the elements in List
        System.out.println(myList);
    }
}


Output:

[3.2, 5.5, 7.6]

Reference: https://google.github.io/guava/releases/19.0/api/docs/com/google/common/primitives/Doubles.html#asList(double…)

RELATED ARTICLES

10 COMMENTS

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS