Bhavesh Sangwan wrote:Hi Experts ! I'm working on shopping-cart and trying to write a function to search a specific product based on its "p_id" field.
...
I have some idea....
1. SHould I implement Comparator interface....
2. Should I use arraylist.binarySearch()
Or Something else....?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Bhavesh Sangwan wrote:OK then for each search - first sort arraylist and then apply binarysearch method on that sorted list.....Right ?
Sir ! According to my knowledge, Comparator and Comparable interface helps us in SORTING an object from any collection...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:If you need to keep the order in your list unchanged, you will have to use linear search, which Lists already support, or copy the List and sort it.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:But he said he was searching a List.
I do not believe that LinkedHashSet is an entity, I believe it is a combination of a List and a Set. But that is only my own eccentric opionion
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Quite probably. Most of the other collections seem to be a hash map in disguise, so why change the habits of a lifetimeWinston Gutkowski wrote: . . . it's actually a wrapped LinkedHashMap<E, Boolean> in disguise.
I don't know what they teach our UGs about collections here, but I was only taught about ArrayList for my MSc. Any other Collections, I had to teach myself. I think they do actually teach the UGs about the collections framework now.. . . I wonder why it isn't taught about more?
Winston
This tiny ad is wafer thin:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|