# Merging Arrays Vs. Linked List.

• February 26th, 2010, 09:49 AM
Kumarrrr

Can someone tell me how I can go about doing it ?

Assuming we have the following constraints,
and a third one to merge them into;

Also, can a linked list be sorted the same way a array can be sorted?

Code :

```public static int[] MergeArrays(int[] ArrayA, int[] ArrayB) {   int ArrayAindex = ArrayA.length; int[] MergedArray = new int[ArrayA.length + ArrayB.length];   for (int x = 0; x < ArrayAindex; x++) { MergedArray[x] = ArrayA[x]; }   int MergedIndex = ArrayA.length;   for (int i = 0; i < ArrayB.length; i++) { MergedArray[MergedIndex] = ArrayB[i]; MergedIndex++; }   return MergedArray; }```
• March 1st, 2010, 02:20 AM
Json
Re: Merging Arrays Vs. Linked List.
Something like this.

Code :

``` final List<Integer> moreIntegers = new LinkedList<Integer>(); moreIntegers.add(3); moreIntegers.add(4);   final List<Integer> integers = new LinkedList<Integer>(); integers.add(1); integers.add(2);   integers.addAll(moreIntegers);   System.out.println(integers);```

We create two linked lists (integers and moreIntegers). We then add two numbers in moreIntegers and two numbers into integers. After that we add all items in moreIntegers into integers using addAll method.

There you go, two linked lists merged together.

// Json