Home  >  Core Java

Example of Arrays.asList in Java

By Arvind Rai, May 18, 2013
Arrays.asList creates a list with fixed size. It means we cannot add element by add method in the returned list by Arrays.asList. Arrays.asList acts the bridge between Array and List. Because the list returned by Arrays.asList cannot extend size but can use all other methods of List.
AsListDemo.java
package com.concretepage;
import java.util.Arrays;
import java.util.List;
public class AsListDemo {
    public static void main(String[] args) {
      List<String> list=  Arrays.asList("A","B","C","D","E");
      System.out.println(list.size());
      //not allowed
      //list.add("F");
       for(String s: list){
          System.out.println(s);
      }
    }
}
Output
5
A
B
C
D
E
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us