Scala: concatenate ArrayBuffer

If you use a mutable collection in scala, you can append to it with += and ++=, like you might expect.

E.g., here is adding an entry to a list of lists:

val results = ArrayBuffer[List[Any]]()
results +=
  List(
    domain,
    conn.getCipherSuite,
    cert.hashCode,
    cert.getPublicKey().getAlgorithm,
    cert.getPublicKey().getFormat,
    cert.getSigAlgName,
    cert.getSigAlgOID,
    cert.getIssuerDN,
    cert.getSerialNumber,
    cert.getSubjectDN,
    cert.getVersion,
    cert.getNotAfter,
    cert.getNotBefore,
    cert.getPublicKey.getFormat,
    cert.getPublicKey.getAlgorithm,
    cert.getIssuerDN.getName
)

And here is concatenating one list of lists with another:

val allData = new ArrayBuffer[List[Any]]
allData ++= results

Leave a Reply

Your email address will not be published. Required fields are marked *