public class ListTest { public static void main(String[] args) { SLL x = new SLL(); x.prepend(new Integer(4)); x.prepend(new Integer(3)); x.prepend(new Integer(2)); x.prepend(new Integer(1)); x.display(); } } class SLL { private ListNode head; public SLL() { } public String toString() { if (head==null) return null; return head.toString(); } public void display() { System.out.println(head); } public ListNode getHead() { return head; } public void prepend(Object o) { if (head == null) head = new ListNode(o,null); else head = new ListNode(o,head); } } class ListNode { private Object item; private ListNode next; public ListNode(Object o, ListNode n) { item = o; next = n; } public Object getItem() { return item; } public ListNode getNext() { return next; } public void setItem(Object o) { item = o; } public void setNext(ListNode n) { next = n; } public String toString() { String temp = item.toString(); if (next != null) temp += "->" + next.toString(); return temp; } }