transforming linked list to java