How can i merge two sorted array lists in order to produce one sorted array list? The inputs should be in ascending order .. lets say first array [ 2, 4,8,8,15 ] and the other one [ 4, 7, 8, 8, 8, 10] and return the merged array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can i merge two sorted array lists in order to produce one sorted array list? The inputs should be in ascending order .. lets say first array [ 2, 4,8,8,15 ] and the other one [ 4, 7, 8, 8, 8, 10] and return the merged array

20th Dec 2016, 6:50 PM
Serxhio
3 Answers
+ 4
use join() and sort() methods?
20th Dec 2016, 8:14 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
https://code.sololearn.com/cF5qe7lecgkK public static void main(String[] args) { int [] first = {2,4,8,8,15}; int [] second = {4, 7, 8, 8, 8, 10}; int [] merged = new int[first.length + second.length]; System.arraycopy(first, 0, merged, 0, first.length); System.arraycopy(second, 0, merged, first.length, second.length); Arrays.sort(merged); System.out.println(Arrays.toString(merged)); } output: [2, 4, 4, 7, 8, 8, 8, 8, 8, 10, 15]
20th Dec 2016, 9:14 PM
Vladimir Honcharenko
Vladimir Honcharenko - avatar
+ 1
Thanks 😁
21st Dec 2016, 1:20 AM
Serxhio