[Solved] Java passing a value to an array without altering original


Yes, by design. The single-equals means set the left operand to the right operand. The 4th element of Array1 is set to the value of the fourth element of Array2. This changes the contents of the array, though not the structure.

If you’re trying to do a comparison, you’ll want to use == for “is equal?” or != for “is not equal?”. If you want Array2[3] to be set to the value of Array1[3] then just reverse the operands.

solved Java passing a value to an array without altering original