If you ask about passing a collection from java code to jasperreports, the best way is to use:
net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
EDIT:
Full example:
HashMap<String, Object> parameters = new HashMap<>();
List<MyObject> objects = new ArrayList<>();
JRBeanCollectionDataSource jDataSource = new JRBeanCollectionDataSource(objects);
// Load report
ClassPathResource report = new ClassPathResource("/myReport.jasper");
InputStream input = report.getInputStream();
// Fill the report with data
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(input);
JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, jDataSource);
// Export the report to the output
ByteArrayOutputStream output = new ByteArrayOutputStream()
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
exporter.exportReport();
// Return the byte[]
return output.toByteArray();