How's this.
import java.util.*;
public class LinkedListDemo {
LinkedList aLinkedList;
public LinkedListDemo() {
aLinkedList = new LinkedList();
// create some MyDataStructures;
MyDataStructure ds1 = new MyDataStructure(1, "hello", 9.9);
MyDataStructure ds2 = new MyDataStructure(6, "from", 39.9);
MyDataStructure ds3 = new MyDataStructure(34, "a", 7.5);
MyDataStructure ds4 = new MyDataStructure(50, "LinkedList", 7.1);
aLinkedList.add(ds1);
aLinkedList.add(ds2);
aLinkedList.add(ds3);
aLinkedList.add(ds4);
// Iterate through the list, printing each in turn.
Iterator it = aLinkedList.iterator();
while (it.hasNext()) {
MyDataStructure aDataStructure = (MyDataStructure)it.next();
System.out.println(aDataStructure);
}
}
public static void main(String[] args) {
LinkedListDemo linkedListDemo1 = new LinkedListDemo();
}
}
class MyDataStructure {
int number;
String msg;
double value;
public MyDataStructure(int theNumber, String theMsg, double theValue) {
number = theNumber;
msg = new String(theMsg);
value = theValue;
}
public String toString() {
return "number = "+number+" || msg = "+msg+" || value = "+value;
}
}