Java Guava | Longs.asList() method with Examples
The Longs.asList() method of Guava’s Longs Class accepts a long array as a parameter and returns a list which has the fixed size. The returned list is backed by the long 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<Long> asList(long… backingArray)
Parameter: The method accepts a mandatory parameter backingArray which is a long array that is used to back the list.
Return Value: The method Longs.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 Longs.asList() method import com.google.common.primitives.Longs; import java.util.List; class GFG { // Driver's code public static void main(String[] args) { // Creating a Long array long arr[] = { 1 , 2 , 3 , 4 , 5 }; // Using Longs.asList() method to wrap // the specified primitive Long array // as a List of the Long type List<Long> myList = Longs.asList(arr); // Displaying the elements in List System.out.println(myList); } } |
[1, 2, 3, 4, 5]
Example 2:
// Java code to show implementation of // Guava's Longs.asList() method import com.google.common.primitives.Longs; import java.util.List; class GFG { // Driver's code public static void main(String[] args) { // Creating a Long array long arr[] = { 3 , 5 , 7 }; // Using Longs.asList() method to wrap // the specified primitive Long array // as a List of the Long type List<Long> myList = Longs.asList(arr); // Displaying the elements in List System.out.println(myList); } } |
[3, 5, 7]
Recommended Posts:
- Java Guava | Chars.max() method with Examples
- Java Guava | Longs.min() method with Examples
- Java Guava | Chars.min() method with Examples
- Java Guava | Chars.contains() method with Examples
- Java Guava | Floats.min() method with Examples
- Java Guava | Doubles.min() method with Examples
- Java Guava | Booleans.contains() method with Examples
- Java Guava | Shorts.contains() method with Examples
- Java Guava | Shorts.max() method with Examples
- Java Guava | Shorts.min() method with Examples
- Java Guava | Floats.contains() method with Examples
- Java Guava | Bytes.contains() method with Examples
- Java Guava | Longs.max() method with Examples
- Java Guava | Longs.contains() method with Examples
- Java Guava | Doubles.max() method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.