Campbell Ritchie wrote:Are you suggesting that the documentation comments might be mistaken? I am aware of errors in other documentation comments, particularly older ones.
Campbell Ritchie wrote:Does ArrayList have an insert() method? If you use ctrl‑F‑insert, it finds the descriptions of the various add(...) methods.
I looked at the output of the code.
Close to what I want.
Paul Clapham wrote:If you use 1 (because copying the 64 elements is "blindingly fast" as Martin said) then you end up with O(1) -- the copying occurs only for powers of 2 so the cost is 1/2 + 1/4 + 1/8 + ... (That's what they mean by "amortized constant time").
Paul Clapham wrote:But if you use 64 then you end up with O(log N) -- the cost is 2/2 + 4/4 + 8/8 + ... (as the mathematicians say, the proof of this is "left as an exercise for the student").
Campbell Ritchie wrote:Thank you, Martin; that would be linear time then. But why does ArrayList say amortised constant time, then?
JDK 13 doc wrote:The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation.
Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an ArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.
Campbell Ritchie wrote:But insertion into an array list is usually regarded as amortised constant time
Piet Souris wrote:Two other quick questions:
1) are the letters always consequtive? Or can we have, say, 1A, 1C, 1Q?
2) are the letters always in alphabetic order, like 1A, 1B, 1C? Or is 1C, 1A, 1B possible?
Sorry if these questions are already answered, I might have missed them.
Junilu Lacar wrote:So how does 300A, 301B, 302C get merged? Would it be [300-301][A-C]?
Janeice DelVecchio wrote:Java with spring boot and poi. Could have been done in any language that has a library for word doc. If it were docx, I would have used straight xml traversal.
Jeanne Boyarsky wrote:We are writing a book about Java. Using another language on the book would be heresy
"51/1" ve "51/2" "51 / [1-2]" No need to edit it.
S Fox wrote:i could avoid doing any sorting at all if i insert each result into an arraylist in the correct position as soon as it's generated. the list must be locked to do this. i could use a binary search to find where to insert at. this should prevent needing to traverse the list. the insert will then shift everything down and dynamically resize the array if needed. each search/insertion will need to happen about 5k times per second per worker.
Are you sure you want to create a new instance of Random every time you need a random number?
i didn't think about the cost of making this new object every time![]()
also i just noticed that there's a special randomization object for multi-thread apps. i think i should be using that one instead.
ThreadLocalRandom