1928/how-can-i-convert-an-arraylist-string-to-string-in-java
List<String> list = new ArrayList<String>(); String[] array = list.toArray(new String[0]);
For example:
List<String> alist = new ArrayList<String>(); alist.add("India"); alist.add("USA"); String[] stringArray = alist.toArray(new String[0]);
The toArray() method without passing any argument returns Object[].
So you have to pass an array as an argument.
In Java 8 or later:
String listString = String.join(", ", list);
In case the list is not of type String, a joining collector can be used:
String listString = list.stream().map(Object::toString).collect(Collectors.joining(", "));
Here are two ways illustrating this: Integer x ...READ MORE
Hi @Daisy You can use Google gson for more ...READ MORE
Hello @kartik, We can use the parseInt(String str) method of ...READ MORE
String[] source = new String[] { "a", ...READ MORE
We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE
Yes; the Java Language Specification writes: In the Java ...READ MORE
Try this: String[] strArray = arrayList.toArray(new Str ...READ MORE
You can use this method: String[] strs = ...READ MORE
Either: Foo[] array = list.toArray(new Foo[list.size()]); or: Foo[] array = ...READ MORE
public static String reverse(String s) { ...READ MORE
OR
Already have an account? Sign in.