What will be the output of following quiz on ArrayList ?
Time limit: 0
Quiz-summary
0 of 1 questions completed
Questions:
1
Information
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);
}
}
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
Time has elapsed
Categories
Not categorized0%
1
Answered
Review
Question 1 of 1
1. Question
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);
}
}
Click button below to answer the quiz and see correct answer :
Correct
Arrays.asList() returns a fixed-size list backed by the specified array. Therefore, the arraylist can’t grow. So, when add() is called, an exception is thrown.
Incorrect
Arrays.asList() returns a fixed-size list backed by the specified array. Therefore, the arraylist can’t grow. So, when add() is called, an exception is thrown.
[…] 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) […]
[…] Java Quiz 38 […]
[…] Java Quiz 38 (Array to ArrayList) […]
[…] 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) […]