2

I have a List<Map<String, Object>> data.

public List<Map<String, Object>> selectAll(String tableName) throws SQLException{
    MapListHandler mapListHandler = new MapListHandler();
    QueryRunner queryRunner = new QueryRunner();
    List<Map<String, Object>> list = queryRunner.query(DBConnection.getConnection(), SELECT + tableName, mapListHandler);
    System.out.println(list);
    return list;
}

Then I get this

List<Map<String, Object>> data = databaseMetadata.selectAll(buttonElements.getTables_in_migrate_schema());

And I need to add it to JTable as rowData so it has to be String[][].

I tried to make something like this.

JTable jTable = new JTable((Object[][]) data.toArray(), fields.toArray());

Can someone please say me how to convert? Thanks in advance!

2
  • 1
    List<Map> is 3D. String[][] is 2D. Can you show us what have you tried(code)? Commented Sep 14, 2020 at 12:51
  • 1
    What part of data do you want to see in e.g. column 5 of row 2? It's not at all obvious how you want that structure mapped to a JTable. Commented Sep 14, 2020 at 13:00

1 Answer 1

1

As you already have the field's name, so just collect every map's value of list and collect as 2D Object array. You can use Stream API this way

Object[][] objList = data.stream().map(m -> m.values().toArray()).toArray(Object[][]::new);
Sign up to request clarification or add additional context in comments.

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.