I’m facing a micro-optimisation where I’m calling contains frequenly on a LinkedList. Would it be a good idea to just change it to a LinkedHashMap?
Note: I’m only adding and checking if the list contains a certain value.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is a bit more complex then “just a
LinkedListwith average-caseO(1)contains”, but essentially – functionality speaking yes.A
LinkedHashMapallowsO(1)contains, and keeps elements in order they were inserted – same as aLinkedList. You might also want to have a look onLinkedHashSetHowever, you might be facing problems if you will want duplicate entries. A
LinkedHashMapandLinkedHashSetare implementingSetandMapinterfaces, and not theListinterface, so they do not allow duplicates.