Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "copy" an array operation to another array?

Tags:

java

arrays

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!

like image 602
Lukas Arvidsson Avatar asked Apr 04 '13 09:04

Lukas Arvidsson


People also ask

Which method is used to copy data from one array to another array?

Using System. Java's System class has a method called “ArrayCOpy” that allows you to copy elements of one array to another array.

Can you copy an array to another array C++?

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.

How do I move an element from one array to another?

So to move an array element from one array position to another we can splice() method or we can simply use array indexing ([]).


1 Answers

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?

like image 160
BambooleanLogic Avatar answered Sep 18 '22 12:09

BambooleanLogic