@Test public void first() { { List<String> from = Arrays.asList("a", "b", "c"); SingleLinkedList<String> list = new SingleLinkedList<>(from); assertThat(list.first(), is("a")); } { SingleLinkedList<String> list = new SingleLinkedList<>(); try { list.first(); fail(); } catch (NoSuchElementException e) { } } }
public E first() { if (isEmpty()) { throw new NoSuchElementException(); } return head.value; }
SingleLinkedList implements Iterable<E>, Serializable { public E first() { if (isEmpty()) { throw new NoSuchElementException(); } return head.value; } }
SingleLinkedList implements Iterable<E>, Serializable { public E first() { if (isEmpty()) { throw new NoSuchElementException(); } return head.value; } SingleLinkedList();  SingleLinkedList(List<? extends E> list);  SingleLinkedList(Iterable<? extends E> iterable); private  SingleLinkedList(Node<E> head); }
SingleLinkedList implements Iterable<E>, Serializable { public E first() { if (isEmpty()) { throw new NoSuchElementException(); } return head.value; } 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 E first() { if (isEmpty()) { throw new NoSuchElementException(); } return head.value; } 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();  }