“Java Toarray” Code-Antworten

Java ArrayList zu Array

List<String> list = new ArrayList<>();
list.add("a");
list.add("ab");
list.add("abc");
list.add("abcd");
// convert
String[] array = list.toArray();
Dark Dove

Arraylist zu Array Java

ArrayList<String> ArrayLister=new ArrayList<>(){ArrayLister.add("Hi")};
String[] array=ArrayLister.toArray(String[]);
BucketofJava

Java Toarray

import java.util.*;
 
public class Scaler {
 
   public static void main(String[] args) {
       ArrayList<Integer> list = new ArrayList<>();
       list.add(1);
       list.add(2);
       list.add(3);
       list.add(4);
       //Implementing the first way to convert list to array in java
       Object[] res1Arr=list.toArray();
       //Implementing the second way to convert list to array in java
       Integer[] res2Arr = new Integer[4];
       list.toArray(res2Arr);
       //Printing the first array
       System.out.println("Printing 'res1Arr':");
           for(Object obj: res1Arr)
           //Typecasting required for the first method
               System.out.println((Integer)obj);
       //Printing the second array
       System.out.println("Printing 'res2Arr':");
           for(Integer i: res2Arr)
               System.out.println(i);
   }
}
codelearner

Ähnliche Antworten wie “Java Toarray”

Fragen ähnlich wie “Java Toarray”

Weitere verwandte Antworten zu “Java Toarray” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen