- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Ints asList() function in Java
The asList() method of the Ints class in Java Guava’s returns a fixed-size list backed by the specified array. The syntax is as follows −
public static List<Integer> asList(int[] arr)
Here, arr is the array to back the list.
Let us see an example to implement the asList() method of the Ints class −
Example
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); } }
Output
Array = 20 30 40 60 80 90 120 150 List = [20, 30, 40, 60, 80, 90, 120, 150]
Advertisements