iterator through linked list in java

https‮//:‬www.lautturi.com
iterator through linked list in java
public class BasicLinkedList<T> implements Iterable<T> {
public int size;

private class Node {
    private T data;
    private Node next;

    private Node(T data) {
        this.data = data;
        next = null;
    }
}

private Node head;
private Node tail;

public BasicLinkedList() {
    head = tail = null;
}
//Add, remove method 

public Iterator<T> iterator() {
    return new Iterator<T>() {

        Node current = head;

        @Override
        public boolean hasNext() {
            return current != null;
        }

        @Override
        public T next() {
            if(hasNext()){
                T data = current.data;
                current = current.next;
                return data;
            }
            return null;
        }

        @Override
        public void remove(){
            throw new UnsupportedOperationException("Remove not implemented.");
        }

    };
    
}
Created Time:2017-09-16 21:48:30  Author:lautturi