private static LinkedList merge(LinkedList ls, LinkedList ls2) { Node temp1 = ls.getFirst(); Node temp2 = ls2.getFirst(); LinkedList ls3 = new LinkedList(); while (temp1 != null && temp2 != null) { if ((Integer.parseInt(temp1.element.toString())) < (Integer.parseInt(temp2.element.toString()))) { ls3.addLast(temp1.element); temp1 = temp1.next; } else { ls3.addLast(temp2.element); temp2 = temp2.next; } } if (temp1 == null) temp1 = temp2; while (temp1 != null) { ls3.addLast(temp1.element); temp1 = temp1.next; } return ls3; }