Andy provided as.java, a shorter variation of Ron's solution using an ArrayList instead of a linked list.