jjenkov / java-resizable-array

A resizable array implemented in Java.
Apache License 2.0
38 stars 27 forks source link

Update ResizableArray.java #1

Closed ZeroMoreFree closed 6 years ago

ZeroMoreFree commented 6 years ago

since the loop "while(length + remaining > capacity)" will return -1 or let the capacity > length + remaining

then if the program is not return -1 , "capacity - length > remaining " come into existence so it is no need for you to use the Math.min function to get a result

jjenkov commented 6 years ago

Ah, now I get it. What you are saying is, that since the while-loop above will either continue running until capacity > length + remaining (or return -1 if expansion fails), by the time the while loop exits and we get to copying the bytes, it is guaranteed that length + remaining < capacity, so there will always be space for the bytes from the ByteBuffer in the ResizableArrayBuffer...

You are right! Thanks! :-)

ZeroMoreFree commented 6 years ago

That's exactly what I want to say. Thank you for your reply. It's a good tutorial

jjenkov commented 6 years ago

Merged in! Thanks again! :-)