Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I copy the contents of an array (with primitive type contents) to another array?

array Contents copy Primitive type
0
Posted

How do I copy the contents of an array (with primitive type contents) to another array?

0

. Use the method java.lang.System.arraycopy(Object src, int src_position, Object dst, int dst_position, int length); Note that there is no corresponding method to clear an array to 0.0, 0, null, false, ‘\u0000’ etc. This has lead several people to suggest the old COBOL trick of “initialize by rollup”. In initialize by roll-up, the programmer sets the first element of the array to the desired value, and then moves elements array[0 to n-1] to array[1 to n]. Under some old IBM COBOL compilers, code was generated to move element 0 to 1, then 1 to 2, and so on, “rolling up” the desired value through the array. It was always a terrible idea, as it went outside the boundaries of defined behavior in COBOL, and was subject to being broken in any compiler release. In any event, intialization by roll-up is defined not to work in Java. If the src and dst arguments refer to the same array object, then the copying is performed as if the components at positions srcOffset through srcOffset+length-1 we

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123