I thought that linked lists should have been faster than arraists when adding items? I just checked how long it takes to add, sort and search for elements (arraylist vs linkedlist vs hashset). I just used java.util classes for arraylist and linked list ... using both add (object) methods available for each class.
arraylist out did a linked list when filling out a list ... and in a linear list search.
Is that right? I did something wrong in the implementation, maybe?
*************** EDIT ******************
I just want to make sure that I use these things correctly. that's what I'm doing:
public class LinkedListTest { private List<String> Names; public LinkedListTest(){ Names = new LinkedList<String>(); }
Then I just use the linked list methods, that is, "Names.add (strings)". And when I tested the arraists, it is almost identical:
public class ArrayListTest { private List<String> Names; public ArrayListTest(){ Names = new ArrayList<String>(); }
Am I doing it right?
java optimization arraylist linked-list
user618712
source share