I have two vectors of numbers, aBuffer
and aCandidato
. Depending on a condition (external to the vector), I need to have aBuffer
receive the contents of aCandidato
to work on it later. aBuffer
will be used by a function that is already ready to receive a vector of numbers, 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 know only aadd
, which adds an element to 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 in an intermediate vector, then doing the flatten
(throwing the result in aBuffer
) similar to this answer in Python, but I do not see this as being elegant.