merge sorted array in Java, a little mess