Merge integer and char array | Selenium Forum
M
Posted on 25/02/2016
Please help me with answer to below questions:
Write a Java program to merge and display two arrays, where one array has integer and other has characters

M
Replied on 25/02/2016

try some thing like this

http://javarevisited.blogspot.in/2013/02/combine-integer-and-string-array-java-example-tutorial.html


http://stackoverflow.com/questions/33819500/i-am-trying-to-merge-to-integer-strings-but-dr-java-the-program-i-am-using-won


M
Replied on 28/02/2016

Thanks for your reply.
But none of the links have example to merge a integer array with character array.

they have code for merging integer arrays and another program to merge character arrays

Please help


M
Replied on 28/02/2016

String[] first = { "1", "2", "3", "4" };
int[] second = { 5, 6, 7, 8 };
String a = Arrays.toString(second); // toString the List or Vector
String ar[] = a.substring(1, a.length() - 1).split(", ");
System.out.println(Arrays.toString(ar));

// combine two arrays in Java using Apache commons ArrayUtils
String[] combined = ArrayUtils.addAll(first, ar);

System.out.println("First array : " + Arrays.toString(first));
System.out.println("Second array : " + Arrays.toString(second));
System.out.println("Combined array : " + Arrays.toString(combined));