我有以下代码:
clientTableList = new Object[DBQueries.getAllClients().size()][3]; [I want to load 3 records for now]
LinkedHashMap<String, LinkedHashMap<String, String>> ClientHashMap = DBQueries.getAllClients();
System.out.println(clientHashMap.keySet());
//Printing all Values
System.out.println(clientHashMap.values());
结果:
[Bob Hope, Elena Hairr, Blossom Kraatz, Loreen Griepentrog]
[{UserID=2345, GivenName=Bob, FamilyName=Hope, DateOfBirth=August 30, 1963, NameSuffix=Sr, NamePrefix=, Email=francoise.rautenstrauch@rautenstrauch.com, Phone=519- ...
我需要加载JTable
,我的下一个代码是:
for (int i = 0; i < clientHashMap.size(); i++) {
clientTableList[i] = new Object[] {
clientHashMap.get("GivenName") + " " + clientHashMap.get("FamilyName"),
clientHashMap.get("LoginEmail") + " ",
clientHashMap.get("Phone") + " "
};
但我为null
获取了所有clientTableList
。
我需要将所有值加载到HashTable
,然后将HashTable
加载到clientTableList
。正确?
答案 0 :(得分:1)
您的clientTableList
没有这些字段,只有其值包含这些字段:
int i = 0;
for (Map<String, String> client: clientHashMap.values()) {
clientTableList[i++] = String.format("%s %s %s %s",
client.get("GivenName"),
client.get("FamilyName"),
client.get("LoginEmail"),
client.get("Phone"));
};
答案 1 :(得分:0)
以下变更有效:
clientTableList[i++] = new Object[]{ client.get("GivenName") + " " + client.get("FamilyName") , client.get("LoginEmail") + " " , client.get("Phone") + " " };