Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java array to collection

// Convert an Array into Collection in Java
 
// import java util library
import java.util.*;
 
// class for writing logic of the problem
public class ArrayToCollection {
    public static void main(String args[])
    {
        // array input
        String playersArray[]
            = { "Virat", "Sachin", "Rohit", "Bumrah" };
       
        // printing input elements for comparison
        System.out.println("Array input: "
                           + Arrays.toString(playersArray));
       
        // converting array into Collection
        // with asList() function
        List playersList = Arrays.asList(playersArray);
       
        // print converted elements
        System.out.println("Converted elements: "
                           + playersList);
    }
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #java #array #collection
ADD COMMENT
Topic
Name
4+5 =