Category Archives: arraylist

Stop an ArrayList from gathering multiple data instead of one in Excel, Apache POI

I'm importing an Excel file and trying to gather data in the cells in one single column, like this:

image 1

When I attempt to do so, somehow, with the code down below, I get the following results:

image 2

Is there a way that I could possibly just get [Teacher's name, HELLO, as, asd]?

HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
int temp = sheet.getPhysicalNumberOfRows();
int numberoftickets = temp - 1;

List < String > a = new ArrayList < String > ();
for (Row row: sheet) {
    Cell c = row.getCell(0);
    if (c.getCellType() == Cell.CELL_TYPE_STRING) {

String[] simpleArray = a.toArray(new String[a.size()]);
String aa = Arrays.toString(simpleArray);
StringTokenizer t = new StringTokenizer(aa, ",");