Java Quiz 38 ( ArrayList)

What will be the output of following quiz on ArrayList ?

 

package com.javatutorial.quiz;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Quiz38 {

  public static void main(String[] args) {

    List<Integer> list = new ArrayList<Integer>();
    
    Integer[] arr = {2,10,3};
    
    list = Arrays.asList(arr);
    
    list.set(0, 3);
    
    System.out.println(list);
    
    list.add(1);
    
    System.out.println(list);
  }

}

© 2016, https:. All rights reserved. On republishing this post, you must provide link to original post

3 comments

  1. […] Java Quiz 38 (Array to ArrayList) […]

  2. […]   Running this program will print the arraylist elements as: [2, 10, 3]     Here is a puzzle on Arrays.asList() that you may like :   Java Quiz 38 (Creating ArrayList from an Array) […]

Leave a Reply.. code can be added in <code> </code> tags

%d bloggers like this: