3394/how-to-convert-a-list-to-an-array-in-java
If you want an array of primitive data type, then execute the code given below.
List<Integer> list = ...; int[] array = new int[list.size()]; for(int i = 0; i < list.size(); i++) array[i] = list.get(i);
String[] strings = list.stream().toArray(String[]::new);
Either:
Foo[] array = list.toArray(new Foo[list.size()]);
or:
Foo[] array = new Foo[list.size()]; list.toArray(array); // fill the array
Another workaround if you use apache commons-lang: int[] ...READ MORE
Use java.util.Arrays: String res = Arrays.toString(array); System. ...READ MORE
Use the lines of code mentioned below:- String ...READ MORE
Hi@MD, The most straightforward way to convert a ...READ MORE
Yes; the Java Language Specification writes: In the Java ...READ MORE
We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE
Use like this. List<String> stockList = new ArrayList<String>(); stockList.add("stock1"); stockList.add("stock2"); String[] ...READ MORE
You can use this method: String[] strs = ...READ MORE
int[][] multi = new int[5][]; multi[0] = new ...READ MORE
In Java 8 or later: String listString = ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.