Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
how to convert Object array to String array in java
As list.toArray() returns an Object[], it can be converted to String array by passing the String[] as parameter. See the example below.
import java.util.ArrayList;
import java.util.List;
public class Tester {
public static void main(String[] args) {
List<String> data = new ArrayList<String>();
data.add("A");
data.add("B");
data.add("C");
//Object[] objects = data.toArray();
String[] strObjects = data.toArray(new String[0]);
for(String obj: strObjects) {
System.out.println(obj);
}
}
}
Output
A B C
Advertisements
