This is probably a simple question, but I have two arrays of approx 1000 elements each, they are called posXArray
and posYArray
. I want to sort posYArray
numerically (lowest number first) but I want the elements of posXArray
to have the same operation applied to them...
For example, if element [56] of posYArray
is the smallest one , I want element [56] of posXArray
to also be moved to [0].
How is this implemented in Java in an easy/good way?
Thank you very much for you help!
Using System. Java's System class has a method called “ArrayCOpy” that allows you to copy elements of one array to another array.
How to Copy an Array in C++ In C++ an array can be copied manually (by hand) or by using the std::copy() function, from the C++ algorithm library. In computer programming, there is shallow copying and there is deep copying. Shallow copying is when two different array names (old and new), refer to the same content.
So to move an array element from one array position to another we can splice() method or we can simply use array indexing ([]).
Since the arrays seem to contain X and Y coordinates, perhaps a better choice is to create a coordinate class containing both values, implement Comparable
and just have a single array to sort using the built-in algorithms?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With