Printing out a Linked list

java, linked-list, printing, string

Solution

If your list implements the java.util.list interface you can use, this line to convert the list to an array and print out the array.

System.out.println(Arrays.toString(list.toArray()));

Problem

When I try to print out my linked list of objects it gives me this: linkedlist.MyLinkedList@329f3d Is there a way to simply overide this to print as Strings? ``` package linkedlist; import java.util.Scanner; public class LinkedListTest { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String item; MyLinkedList list = new MyLinkedList(); System.out.println("Number of items in the list: " + list.size()); Object item1 = "one"; Object item2 = "two"; Object item3 = "Three"; list.add(item1); list.add(item2); list.add(item3); System.out.println("Number of items in the list: " + list.size()); System.out.println(list); } ```

Original source

Related problems