protected ArrayList<K> processMergeList(ArrayList<K> list1,ArrayList<K> list2){
  if (list1 == null) {
    return list2;
  }
  if (list2 == null) {
    return list1;
  }
  ArrayList<K> result=new ArrayList<K>();
  int index1=0;
  int index2=0;
  while (true) {
    if (index1 == list1.size()) {
      while (index2 < list2.size()) {
        result.add(list2.get(index2++));
      }
      break;
    }
    if (index2 == list2.size()) {
      while (index1 < list1.size()) {
        result.add(list1.get(index1++));
      }
      break;
    }
    K val1=list1.get(index1++);
    K val2=list2.get(index2++);
    K[] vals=compare(val1,val2);
    result.add(vals[0]);
    if (vals[1] != null) {
      result.add(vals[1]);
    }
  }
  return result;
}

protected ArrayList < K > processMergeList ( ArrayList < K > list1 , ArrayList < K > list2 ) { if ( list1 == null ) { return list2 ; } if ( list2 == null ) { return list1 ; } ArrayList < K > result = new ArrayList < K > ( ) ; int index1 = 0 ; int index2 = 0 ; while ( true ) { if ( index1 == list1 . size ( ) ) { while ( index2 < list2 . size ( ) ) { result . add ( list2 . get ( index2 ++ ) ) ; } break ; } if ( index2 == list2 . size ( ) ) { while ( index1 < list1 . size ( ) ) { result . add ( list1 . get ( index1 ++ ) ) ; } break ; } K val1 = list1 . get ( index1 ++ ) ; K val2 = list2 . get ( index2 ++ ) ; K [ ] vals = compare ( val1 , val2 ) ; result . add ( vals [ 0 ] ) ; if ( vals [ 1 ] != null ) { result . add ( vals [ 1 ] ) ; } } return result ; }
sorted parameter list are merged into sorted merged output list .
