0

I have a ArrayList of objects. Suppose, the object is a class something like this...

public class User {

     String userId;
     String name;
     String account_created;
     String date_Of_Birth;

     //setters and getters
  }

Iam inserting the data into the list from an external source (like database)

List<User> usersList = new UserManager().totalUsersList();

I created a new Array for columns

String[] columns = new String[] { "Id", "Name", "Account Created", "Date of Birth" };

Iam want to send the List data into multidimensional array. Something like ...

String[][] usersData = new String[usersList.size()][4];

for (User user : usersList) {
    //usersData = usersData + {"","","",""} ; --> Need to add data into Array while iterating the over the list
}

How can i send data from List into the array : usersData

Iam sending the data into an array for displaying in a JTable(Swing).

Any Suggestions ...... ???

0

2 Answers 2

2

Any Suggestions ...... ???

Don't. Maintain the structure of the data and create a custom TableModel (extending from something like AbstractTableModel) and use the List<User> as the data buffer

See How to Use Tables for more details and this for example

Sign up to request clarification or add additional context in comments.

Comments

1

You need a traditional for loop in order to use the indices :

for (int i=0; i<usersList.size(); i++) {
    User userTO = usersList.get(i);
    usersData[i] = new String[] {usetTO.getUserID(),...,...,...};
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.