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 list mergeAndSort(List<integer> list1, List<integer> list2){
List<integer> list3;
int list2Size = list2.size();
for(int i=0;i<list2Size;i++){
    list1.add(list2(i));  
}
// Here we got all the elements in 1 list i.e list1

int list1Size = list1.size();
for(i=0;i<list1Size;i++){
    int small = 0;
    for(int j=i;j<list1size;j++){
        if(list1(i)> list2(j)){
            small = list2(j;
        }
    }
    list3.add(small); //Smallest 1 will be added to the new list
}

```

}
```
     ArrayList<Integer> a = new ArrayList();
     ArrayList<Integer> b = new ArrayList();
     ArrayList<Integer> c = new ArrayList();

     a.add(1);
     a.add(3);
     a.add(5);
     a.add(7);
     a.add(17);
     a.add(27);
     a.add(37);

     b.add(0); 
     b.add(2);
     b.add(4);

     while( a.size() > 0 || b.size() >0){

        if( a.size() == 0 || b.size() == 0){
            c.addAll(b);
            c.addAll(a);
            break;
        }

        if(a.get(0) < b.get(0)){
            c.add(a.get(0));
            a.remove(0);
        }
        else{
            c.add(b.get(0));
            b.remove(0);
        }

    }

    System.out.println(c.toString());

```