Description
This was a challenge that I posed to myself after learning all about Linked Lists and how they might be implemented. The challenge was to create a Linked List that used the java generics in order for the Linked List to be a compile-time type safe implementation. This provided me with a good learning opportunity for both generics and Linked Lists.
Overall I’m happy with the outcome of the task, as it is works well and it was the first time that I had used implemented generics. The challenge did not take very long to complete but still tested my knowledge on both java references and Linked Lists in general. However, this was more of a pet project, of which I didn't implement the java List interface, so I don't think that I would really use this implementation for any other projects as it is not compatible with other java List classes and the Collections packages.
Examples
Input
//Create the LinkedList
LinkedList ll = new LinkedList();
String string = "Hello world my name is Mark!";
String[] words = string.split(' ');
for(int i = 0; i < words.length; i++) {
ll.add(words[i]);
}
//Print out the list
System.out.println(ll);
//Remove "world"
ll.remove(1);
System.out.println(ll);
//Remove "Hello"
ll.remove(0);
System.out.println(ll);
//Print out all of the words from the LinkedList
for(int i = 0; i < ll.size(); i++) {
System.out.print(ll.get(i) + " ");
}
Output
0: Hello 1: world 2: my 3: name 4: is 5: Mark!
0: Hello 1: my 2: name 3: is 4: Mark!
0: my 1: name 2: is 3: Mark!
my name is Mark!