LinkedList - how to override the contains method?
800790Feb 5 2009 — edited Feb 5 2009Hi all
I think I have a fairly common java problem...
I have a linkedList LL, LL contains a many objects O, each O object contains 2 values - an integer I and a String S
The LL has grown to be quite large, and I am trying to perform a search through the linked list for string S.
So... The problem for me is that I would like to simply call the "contains" method and search for string S! BUT I can't do this because LL is not a <String> LinkedList, it is an <O> LinkedList.
Thus, I inefficiently have been looking at every O object in the list, checking to see if the O's String value was equal to S.
Which is wildly inefficient. I would love to reduce the amount of time of this process... I thought that there may be a simple way to re-implement the contains method of the linked list? But I still don't know if that would help seeing how I am going to be writing it myself and I am not that knowledgable about writing an efficient "contains" method...
Any (related) thoughts?