How an object array can be converted to string array in java?

0 votes

 I use the following code to convert an Object array to a String array :

Object Object_Arr[]=new Obj[100];


String String_Arr[]=new String[Object_Arr.length];

for (int i=0;i<String_Arr.length;i++) String_Arr[i]=Object_Arr[i].toString();

But I wonder if there is another way to do this?

Jun 8, 2018 in Java by Daisy
• 8,050 points
106 views

2 answers to this question.

0 votes

Another alternative could be:

String[] stringArr = Arrays.copyOf(objectArr, objectArr.length, String[].class);
answered Jun 8, 2018 by sophia
• 1,400 points
0 votes
System.arraycopy is the most efficient way, but for aesthetics, I would prefer
Arrays.asList(Object_Array).toArray(new String[Object_Array.length]);
answered Aug 8, 2018 by Sushmita
• 6,880 points

Related Questions In Java

0 votes
3 answers

How can I add new elements to an Array in Java

String[] source = new String[] { "a", ...READ MORE

answered Sep 19, 2018 in Java by Sushmita
• 6,880 points
149 views
0 votes
2 answers
+15 votes
18 answers

How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

answered Feb 7 in Java by Suresh
• 700 points
87,996 views
0 votes
2 answers

How to convert an int array to string using tostring method in java?

Use java.util.Arrays: String res = Arrays.toString(array); System.o ...READ MORE

answered Aug 16 in Java by Sirajul
• 36,620 points
253 views
0 votes
1 answer

How can two strings be concatenated in java?

You can concatenate Strings using the + operator: System.out.println("Your number ...READ MORE

answered Jun 6, 2018 in Java by Daisy
• 8,050 points
23 views
0 votes
1 answer

Why is char[] preferred over a string?

Strings are immutable. That means once you've ...READ MORE

answered Jun 14, 2018 in Java by scarlett
• 1,280 points
31 views
0 votes
1 answer

Can quotes be added in a java string.how?

In Java, you can escape quotes with \: String ...READ MORE

answered Jun 14, 2018 in Java by Akrati
• 960 points
29 views
0 votes
2 answers

How to convert a java string into byte array

Try using String.getBytes(). It returns a byte[] ...READ MORE

answered Aug 22 in Java by Sirajul
• 36,620 points
74 views
0 votes
1 answer

How to print java array in the simplest way?

String[] arr = new String[] {"John", "Mary", ...READ MORE

answered Apr 17, 2018 in Java by sophia
• 1,400 points
84 views
0 votes
1 answer

How to initialize multi-dimensional array in java?

A multidimensional array in Java is really an array ...READ MORE

answered Jun 6, 2018 in Java by sophia
• 1,400 points
36 views