Use like this.

List<String> stockList = new ArrayList<String>();
stockList.add("stock1");
stockList.add("stock2");

String[] stockArr = new String[stockList.size()];
stockArr = stockList.toArray(stockArr);

for(String s : stockArr)
    System.out.println(s);
Answer from Prince John Wesley on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › convert an arraylist of string to a string array in java
Convert an ArrayList of String to a String Array in Java | Baeldung
March 7, 2025 - One straightforward idea to solve our problem is to walk through the string ArrayList, take every element, and fill a predeclared string array.
Discussions

arrays - Converting 'ArrayList<String> to 'String[]' in Java - Stack Overflow
How might I convert an ArrayList object to a String[] array in Java? More on stackoverflow.com
🌐 stackoverflow.com
How can I convert my list<string> to a string[ ] array?
using System.Linq; yoklama.ToArray() More on reddit.com
🌐 r/learncsharp
15
0
October 23, 2024
android - How to Convert arraylist<string> to string[] - Stack Overflow
public SampleGridViewAdapter(Context context,ArrayList urls) { this.context = context; this .urls=urls; Log.i("DDDDDDDDDD",String.valueOf(urls)); simpleArray = urls.to More on stackoverflow.com
🌐 stackoverflow.com
Convert system.collection arrylist to string array
A couple of ways to do this. In particular, it depends on whether you really want an array of strings or just one big string. Let's set up the example: $list = [System.Collections.ArrayList]::new() [void]$list.AddRange(('x','y','z')) For an array of strings, use the ToArray() method: $list.ToArray() You can also pass in the type of the array you want if you want the array to be [string[]] rather than [object[]]: $list.ToArray([string]) But you can also just join the elements of the ArrayList together to get one big string: $list -join "`r`n" More on reddit.com
🌐 r/PowerShell
7
3
September 1, 2020
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-convert-arraylist-to-string-array-in-java
How to convert ArrayList to string array in java
We are converting this arraylist ... names.add("Harsh"); names.add("John"); // ArrayList to Array Conversion using toArray() String arr[]=names.toArray(new String[names.size()]); //Print array elements for(String str: arr) { System.out.println(str); } } }...
🌐
Codemia
codemia.io › home › knowledge hub › convert arraylist to string[] array
Convert ArrayList<String> to String[] array | Codemia
January 2, 2025 - When programming in Java, a common requirement is to convert an ArrayList<String> to a String[] array. This is particularly useful when working with older APIs or libraries that do not accept collections as input.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › convert-an-arraylist-of-string-to-a-string-array-in-java
Convert an ArrayList of String to a String array in Java
import java.util.*; public class Demo { public static void main(String[] args) { ArrayList<String> arrList = new ArrayList<String>(); arrList.add("Bentley"); arrList.add("Audi"); arrList.add("Jaguar"); arrList.add("Cadillac"); arrList.add("Mazda"); arrList.add("Land Rover"); arrList.add("Porsche"); int size = arrList.size(); String res[] = arrList.toArray(new String[size]); System.out.println("String Array..."); for(String s: res) { System.out.println(s); } } }
🌐
Programiz
programiz.com › java-programming › examples › arraylist-string-conversion
Java Program to Convert the ArrayList into a string and vice versa | Programiz
March 14, 2024 - Here, the toString() method converts arraylist into a string. The entire arraylist is converted as a single string. Note: We can also convert the arraylist into a string array.
🌐
Coderanch
coderanch.com › t › 377381 › java › convert-ArrayList-Strings-String
convert an ArrayList of Strings into String[] ? (Java in General forum at Coderanch)
July 31, 2005 - ArrayList aL = getStringObj(); But "aL.toArray();" can only return me an array of Objects ? Of course, I can do Iterator i = aL.iterator(); String s = new String[aL.size()]; int i = 0; while(i.hasNext()) { s[i++] = i.next().toString(); } return s; where "s" is an array of Strings.
🌐
Javatpoint
javatpoint.com › convert-arraylist-to-string-array-in-java
Convert ArrayList to String Array in Java - Javatpoint
Convert ArrayList to String Array in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
W3Docs
w3docs.com › java
Convert ArrayList<String> to String[] array
To convert an ArrayList<String> to a String[] array in Java, you can use the toArray method of the ArrayList class and pass it an empty array of the appropriate type:
🌐
Reddit
reddit.com › r/learncsharp › how can i convert my list to a string[ ] array?
r/learncsharp on Reddit: How can I convert my list<string> to a string[ ] array?
October 23, 2024 -

I am trying to write a simple code that will print out some names alphabetically but I wanna do it using a list.

I know that Array.Sort(); exists but I couldnt find a way to convert my list to an array.

using System; using System.Collections.Generic;

namespace siniflistesi { class Program { static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("12-A sinif listesini gormek icin herhangi bir tusa basiniz."); Console.ReadKey(); Console.Clear();

List<string> yoklama = new List<string>(); string[] thearray = new string[yoklama.Count]; yoklama = Convert."i couldnt find an array option here" (thearray); Array.Sort(yoklama);

yoklama.Add ("Nehir"); yoklama.Add ("Zumra"); yoklama.Add ("Elif");

for (int i = 0; i < yoklama.Count; i++) { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine(yoklama[i]); } Console.ReadKey(); } } }

🌐
Mkyong
mkyong.com › home › java › java – convert arraylist to string[]
Java – Convert ArrayList<String> to String[] | mkyong.com
April 17, 2019 - In the old days, we can use list.toArray(new String[0]) to convert a ArrayList<String> into a String[] · For Java 8, we can do like this :
🌐
Edureka Community
edureka.co › home › community › categories › java › convert arraylist string to string array
Convert ArrayList String to String array | Edureka Community
December 22, 2020 - 100412/convert-arraylist-string-to-string-array · Home · Community · Categories · Java · Convert ArrayList String to String array · how do I turn a double in an array from 1000 to infinity Jul 9, 2024 · I have created a code in java for a flower shop and now my IDE is showing all the inputs are in red showing there is an error Jul 6, 2024 ·
🌐
Edureka Community
edureka.co › home › community › categories › java › how to convert arraylist string to string in...
How to convert ArrayList String to String in Java | Edureka Community
May 21, 2018 - How to convert ArrayList String to String in... how do I turn a double in an array from 1000 to infinity Jul 9, 2024
🌐
Real's HowTo
rgagnon.com › javadetails › java-convert-arraylist-to-string-array.html
Convert ArrayList To a String Array - Real's Java How-to
String[] stringArr = al.toArray(new String[] {}); for (String s: stringArr) System.out.println("** " + s); ... import java.util.List; import java.util.ArrayList; public class ArrayTest { public static void main(String[] args) { List<String> ...
🌐
Stack Overflow
stackoverflow.com › questions › 30136881 › how-to-convert-arrayliststring-to-string
android - How to Convert arraylist<string> to string[] - Stack Overflow
public SampleGridViewAdapter(Context context,ArrayList urls) { this.context = context; this .urls=urls; Log.i("DDDDDDDDDD",String.valueOf(urls)); simpleArray = urls.to
🌐
YouTube
youtube.com › watch
Converting ArrayList of String to a simple 'String[]' array in Java Programming - YouTube
Can you help me to buy a coffee:https://www.buymeacoffee.com/coffeeprogram
Published: October 15, 2022
🌐
Coderanch
coderanch.com › t › 462468 › java › convert-ArrayList-String-String
How to convert ArrayList<String> to String[]? (Beginning Java forum at Coderanch)
September 14, 2009 - If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection. SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6 How To Ask Questions How To Answer Questions