Explanation of Solution
Create list from array of objects:
asList() method is used to create list from a array of objects.
- asList() returns the list of the specified array.
- This method is used to act as the bridge between array elements and collections API (Application
Programming interface) such as ArrayList and Linked List.
Syntax for asList() method:
asList(objectName)
Sample Program:
//Import the required packages
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
//Class definition
public class ListfromArrayobjects
{
//Main method
public static void main(String[] args)
{
// Creating String ArrayObject
String[] ArrayObj = new String[]{"Example","for","asList"};
System.out.println("Before Array object converted to ArrayList:");
/*Printing Arrayobjects before converting it to ArrayList */
for(String s: ArrayObj)
System.out.println(s);
/*Converting Array Object to ArrayList using asList */
ArrayList<String> AL = new ArrayList<String>(Arrays...
Want to see the full answer?
Check out a sample textbook solutionChapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- ArrayList list = new ArrayList(); What is the initial quantity of the ArrayList list? a. 5 b. 10 c. 0 d. 100arrow_forwardWhat is the initial quantity of the ArrayList list?arrow_forwardThe next five questions refer to the following String elements: ["It", "was", "a", "stormy", "night"] Write the code to declare an ArrayList containing these elements. What is the size of the list? What is its type?arrow_forward
- Examine the following code: ArrayList<String> list = new ArrayList<String>(10) ; list.add("A"); list.add("B"); list.add("C"); list.add(0, "E" ); What element will be at index 2 of the list? What list will be printed after executing the method list.remove(2);arrow_forwardHow do you find the lowest and highest values in a list?arrow_forwardIn Kotlin, Create a list that uses your area function as an initializer and contains the areas of circles with each integer from 1 to 25 as radius.arrow_forward
- How well do variables work for handling data lists? What do you think is going on?arrow_forwardPlease write down the output of following code: ArrayList<String> list = new ArrayList<String>(); list.add("10"); list.add("20"); list.add("30"); System.out.println( list.size()); System.out,println( list.get(1));arrow_forwardWrite a statement that creates a two-dimensional list with 5 rows and 3 columns. Then writenested loops that get an integer value from the user for each element in the list.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education