While testing web applications we came across many list of elements or an element with list of data. In such cases we may need the following conversation instead of iterating over an array or a list.
Please refer the below simple example to convert a string array to a list and vice versa. But be careful about the order of elements, If required you may use collection methods to do so.
Lets take an arry of strings as below
Array to List:
List to Array:
Please refer the below simple example to convert a string array to a list and vice versa. But be careful about the order of elements, If required you may use collection methods to do so.
Lets take an arry of strings as below
String[] elementsAsArray = new String[]{"ele1","ele2","ele3"};
Array to List:
ListarrayAsList = Arrays.asList(elementsAsArray);
List to Array:
String[] listAsArray = arrayAsList.toArray(new String[arrayAsList.size()]);
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteJava Training in Chennai Java Training in Chennai | Core Java Training in Chennai
Online Java Training Java Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes