“Java Array to Collection” Kode Jawaban

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);
    }
}
Cédric Hons

cara mengubah koleksi ke array di java

List<String> list = new ArrayList<String>(); // Original list
String[] arr = list.toArray(new String[list.size()]);  // toArray function with array to be populated by this list as an argument.
Wide-eyed Wallaby

Jawaban yang mirip dengan “Java Array to Collection”

Pertanyaan yang mirip dengan “Java Array to Collection”

Lebih banyak jawaban terkait untuk “Java Array to Collection” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya