appends elem to the value of s, and resets s to the result.
- AppendTo[s,elem] is equivalent to s=Append[s,elem].
- AppendTo has attribute HoldFirst.
- You can use AppendTo repeatedly to build up a list, though Sow and Reap will usually be more efficient. »
- AppendTo works on SparseArray objects, returning ordinary lists if necessary. »
- AppendTo works on Association objects, just like Append.
Examplesopen allclose all
Basic Examples (2)
Append to an Association:
Generalizations & Extensions (3)
Use a head other than List:
Possible Issues (6)
Using AppendTo on a column of a matrix replaces column values:
Using AppendTo to accumulate values in large loops can be slow:
When working on a shared list in parallel, AppendTo is atomic:
The seemingly equivalent expression using Append is not atomic: