Question: In my assignment the third step is to Call the method merge to merge the two lists in list1 so that the list1 **remains sorted.**

I write my code but it doesn't work well , the output show wrong because it important to be sorted 

```
 public static void merge (ArrayList<Integer> list1, ArrayList<Integer> list2)
 {
        int i;
        int n=list1.size();
        int pos , j=0;

        for (pos =0 ;pos<n ; pos++)
        {
            for ( i=0 ; i<n ; i++)
                if (list1.get(j)>list2.get(pos))
                    list1.add(pos,list2.get(pos));
                else 
                    j++;
       } 
 }

```

Answer: 
```
public static void merge (ArrayList<Integer> list1, ArrayList<Integer> list2)
{
    list1.addAll(list2);
    Collections.sort(list1);
}

```
If your input Lists aren't too long, I'd suggest just merging the lists and using the `Collections.sort()` Method to restore the order:

```
public static void mergeAndSort(List<Integer> list1, List<Integer> list2) {
    List<Integer> combinedList = new ArrayList<Integer>(list1);
    combinedList.addAll(list2);
    Collections.sort(combinedList);
    return combinedList;
}

```

As a sidenote, you should use the `List` interface instead of the `ArrayList` implementation class wherever possible.