Stephan van Hulst wrote:It's the result of a search in a sorted sequence. An unsorted sequence wouldn't have an insertion point for an element that wasn't found.
Winston Gutkowski wrote:the name suggests to me that your class is part of a broader set of "search results" which don't necessarily have to be "sorted".
And that's where we disagree. int is not a natural choice for a search result. Integer (yuck) or OptionalInt (better) might be when the search doesn't have to return an insertion point. When it does, a value of -4 to indicate an insertion point at index 3 is everything but natural.
I find it confusing that your foundAt() method returns an index when the element wasn't found, and that the insertAt() method does not return an index when the element was found, even though it's perfectly fine to insert an element with the same value before the found element.
Stephan van Hulst wrote:Well, they could have returned an object like I demonstrated with SortedSequenceSearchResult, and they could have done it all the way back in Java 1.2.
Stephan van Hulst wrote:What gave me a headache is the terrible way they return the value...
Pablo Napoli wrote:Is this right for you?.
Stephan van Hulst wrote:List.sort() accepts a Comparator<? super T> and not a Comparator<T>, because if it just so happens that I have a Comparator<Fruit> which sorts fruits by sweetness and I have a List<Strawberry>, then why shouldn't I be allowed to sort the strawberries with the comparator I already have?
Biniman Idugboe wrote:Is ? super T a single parameter?
Dawid Smith wrote:Thank you guys for all the feedback.
Arun Singh Raaj wrote:because I want to know why insertion is slower in ArrayList. I understand in case of arrays that to insert a new element it has to shift rest all elements because they are stored in contiguous locations but ArrayList is a dynamic array so I guessed it also stores elements in contiguous locations.
warren brandt wrote:i have come up with a small project for myself (though i'm sure its been done before)
I want to develop an ATM machine application...
Biniman Idugboe wrote:
Arun Singh Raaj wrote:I want to know, Since ArrayList is backed by array data-structure, do ArrayList elements get stored in contiguous locations similar to array's?
Dawid Smith wrote:Hello. I've attempted to code a recursive version of a binary search algorithm. It seems to be working, but I would love to hear feedback from you guys.
wayne brandon wrote:I just dont understand what you mean here, can you please explain
John Eipe wrote:I read in a book that end of file could be given as input for a program. For Windows, it's <Ctrl> + Z.
But it never works.