@Test public void concat() { { SingleLinkedList<String> list0 = new SingleLinkedList<>(); assertThat(list0.size(), is(0)); SingleLinkedList<String> list1 = list0.concat("a"); assertThat(list0.size(), is(0)); assertThat(list1.size(), is(1)); assertThat(list1.get(0), is("a")); SingleLinkedList<String> list2 = list1.concat("b"); assertThat(list0.size(), is(0)); assertThat(list1.size(), is(1)); assertThat(list1.get(0), is("a")); assertThat(list2.size(), is(2)); assertThat(list2.get(0), is("b")); assertThat(list2.get(1), is("a")); SingleLinkedList<String> list3 = list2.concat("c"); assertThat(list0.size(), is(0)); assertThat(list1.size(), is(1)); assertThat(list1.get(0), is("a")); assertThat(list2.size(), is(2)); assertThat(list2.get(0), is("b")); assertThat(list2.get(1), is("a")); assertThat(list3.size(), is(3)); assertThat(list3.get(0), is("c")); assertThat(list3.get(1), is("b")); assertThat(list3.get(2), is("a")); } { List<String> from = Arrays.asList("a", "b", "c"); SingleLinkedList<String> list = new SingleLinkedList<>(from); assertThat(list.size(), is(3)); assertThat(list.get(0), is("a")); assertThat(list.get(1), is("b")); assertThat(list.get(2), is("c")); SingleLinkedList<String> concat = list.concat("d"); assertThat(list.size(), is(3)); assertThat(list.get(0), is("a")); assertThat(list.get(1), is("b")); assertThat(list.get(2), is("c")); assertThat(concat.size(), is(4)); assertThat(concat.get(0), is("d")); assertThat(concat.get(1), is("a")); assertThat(concat.get(2), is("b")); assertThat(concat.get(3), is("c")); } }
public SingleLinkedList<E> concat(E element) { Node<E> next = new Node<>(element, head); return new SingleLinkedList<>(next); }
SingleLinkedList implements Iterable<E>, Serializable { public SingleLinkedList<E> concat(E element) { Node<E> next = new Node<>(element, head); return new SingleLinkedList<>(next); } }
SingleLinkedList implements Iterable<E>, Serializable { public SingleLinkedList<E> concat(E element) { Node<E> next = new Node<>(element, head); return new SingleLinkedList<>(next); } SingleLinkedList();  SingleLinkedList(List<? extends E> list);  SingleLinkedList(Iterable<? extends E> iterable); private  SingleLinkedList(Node<E> head); }
SingleLinkedList implements Iterable<E>, Serializable { public SingleLinkedList<E> concat(E element) { Node<E> next = new Node<>(element, head); return new SingleLinkedList<>(next); } SingleLinkedList();  SingleLinkedList(List<? extends E> list);  SingleLinkedList(Iterable<? extends E> iterable); private  SingleLinkedList(Node<E> head); boolean isEmpty(); int size(); SingleLinkedList<E> concat(E element); E first(); SingleLinkedList<E> rest(); E get(int index); @Override Iterator<E> iterator(); C fill(C target); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
SingleLinkedList implements Iterable<E>, Serializable { public SingleLinkedList<E> concat(E element) { Node<E> next = new Node<>(element, head); return new SingleLinkedList<>(next); } SingleLinkedList();  SingleLinkedList(List<? extends E> list);  SingleLinkedList(Iterable<? extends E> iterable); private  SingleLinkedList(Node<E> head); boolean isEmpty(); int size(); SingleLinkedList<E> concat(E element); E first(); SingleLinkedList<E> rest(); E get(int index); @Override Iterator<E> iterator(); C fill(C target); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }