This question has already been answered:

There is a JTable with 3 columns and 100 rows. It is necessary for an event on the table to find out what data lie in the second column, i.e. there will be a collection (array) with data. Print in Sytem.out.println (array);

Reported as a duplicate member Nick Volynkin 11 Aug '17 at 4:02 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    It got to!

    List<String> array = new ArrayList<>(); for (int i = 0; i < table.getRowCount(); i++) { array.add((String) table.getValueAt(i, table.getColumnModel().getColumnIndex("Столбец 2"))); } System.out.println(array); 
    • one
      Your option is not correct in terms of architecture. I gave you the right option - you need to use the model, not the display. - Mikhail Vaysman
    • why wrong? What problems can be in this code? - user
    • they also have - architectural, performance problems and data type loss. - Mikhail Vaysman
    • I do not understand what's wrong with this, I checked, the data is not lost, there is just a row counter in the table and a drift of the data I - user
    • It solves the current problem, but at the same time creates several bugs. Therefore, they do not look at the fact that the answer is correct for you; it is not true for others, and that site is a collective base of answers. - Mikhail Vaysman