I am comparing the ArrayList
and LinkedList
.
For eg:
ArrayList => {2,4,5}
LinkedList => 1->3->8->7->6
Final Output => 1->2->3->4->5->8->7->6
I need elements from array list to be compared with elements in linked list and need to insert such that the final linked list is inserted in sorted order using JAVA 8 Streams/Filter/Map/Collections... (I have no idea)
Do not change the order of already existing elements ( in above example 8->7->6 did not change order)
I tried using simple Core java by using two for loops to compare and insert into linked list
for(int i=0;i<arrayList.size();i++){
for(int j=0;j<linkedList.size();j++){
if(linkedList.get(j)>arrayList.get(i)){
linkedList.add(j,arrayList.get(i));
break;
}
}
}
I need code replacement in Java 8 using streams, maps, filters, collections.. etc