Retrieve Data To ArrayList or Array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Retrieve Data To ArrayList or Array

Hi, Not sure if it possible. I'm looking to retrieve or extract my Jtable data to my ArrayList or Array. When I run the code or click a previous or next button the pattern of letters in the table changes. So I want to get that Jtable data to my ArrayList or array. I tried adding a piece of code to try it but I'm not getting any output. Please see attached code: https://code.sololearn.com/c4nPuH9y9uo4/?ref=app

11th Feb 2023, 8:08 PM
Sibusiso Mbambo
1 Answer
0
It looks like the code you provided includes an attempt to extract the data from the JTable and store it in an ArrayList, but this code is not located within a method or event handler, so it will not execute properly. Additionally, it appears to be attempting to extract data from a different table model than the one that is being used to populate the JTable. To extract data from the JTable and store it in an ArrayList, you can add a method to the Calenda class that iterates over the rows and columns of the table and adds each cell value to an ArrayList. Here is an example of what that code might look like: public ArrayList<String> getTableData() { ArrayList<String> tableData = new ArrayList<String>(); for (int row = 0; row < table.getRowCount(); row++) { for (int col = 0; col < table.getColumnCount(); col++) { Object cellValue = table.getValueAt(row, col); if (cellValue != null) { tableData.add(cellValue.toString()); } } } return tableData; }
25th Feb 2023, 5:10 AM
Java Programming Goal
Java Programming Goal - avatar