2
I have two number vectors, aBuffer
and aCandidato
. Depending on a condition (external to the vector), I need aBuffer
receive the content of aCandidato
to work on it afterwards. aBuffer
will be used by a function that is already ready to receive a number array, so I would not like to change it.
In Java, I would do something like this:
ArrayList<Integer> aBuffer = ...;
ArrayList<Integer> aCandidato = ...;
...
if (condicaoMisteriosa()) {
aBuffer.addAll(aCandidato);
}
However, in ADVPL, I only know the aadd
, that adds an element at the end of the array. The code I can do is:
local aBuffer := {}
local aCandidato := {}
local lCondicaoMisteriosa := ...
local i
...
If lCondicaoMisteriosa
For i := 1 len(aCandidato)
aadd(aBuffer, aCandidato[i])
Next i
EndIf
The Java equivalent of this code would be:
ArrayList<Integer> aBuffer = ...;
ArrayList<Integer> aCandidato = ...;
...
if (condicaoMisteriosa()) {
for (int i = 0; i < aCandidato.size(); i++) {
aBuffer.add(aCandidato.get(i));
}
}
The alternative of concatenating the vectors into an intermediate vector, to then do the flatten
(playing the result in aBuffer
) similarly to this answer in Python, but I don’t see it as being elegant.