我有一个Object 2维数组,让我们说Result [] []其中我有2列和多行(动态依赖于数据库)。现在作为一列我每行有1个数组让我们说结果。
Example: column column column
1 hello 1,2,3,4
2 hi 4,3,2,1
3 bye 5,2,1,3,6
所以我需要一个对象作为二维Array对象中的一列。 我没有摆脱问题。
我的代码是:
public Object[][] getGroupDetails(String org_id, Object[][] result) {
Object[][] result2 = null;
Object[][] list = null;
System.out.println(result.length);
Integer len = result.length;
//String groups_id="";
try {
Integer i = 0;
while (i < len) {
String getBelongingGroupsList = "SELECT DISTINCT groups.GROUPS_NAME, groups.GROUPS_ID FROM groups LEFT JOIN member "
+ "ON member.GROUPS_ID=groups.GROUPS_ID WHERE groups.org_id=" + org_id + " AND member.member_number =" + result[i][1];
System.out.println("getBelongingGroupsList " + getBelongingGroupsList);
ResultSet rscheck = (ResultSet) DataService.getResultSet(getBelongingGroupsList);
list = (Object[][]) DataService.getDataFromResultSet(rscheck);
System.out.println("list made");
System.out.println(list.length);//not executing bhai kya hua teko
for (int j = 0; j < list.length; j++) {
System.out.println("copying list to object ");
result[i][j] = list[j][0];
}
//System.out.println(result2[i].length);
//groups_id = rscheck.getString("groups_id");
i++;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
答案 0 :(得分:1)
您可以尝试以下方法。它还存储结果索引。如果这有帮助,请告诉我。
String[] col;
List<String[]> list = new ArrayList<String[]>();
col = new String[3];
col[0] = "1";
col[1] = "hello";
col[2] = "1,2,3,4";
list.add(col);
col = new String[3];
col[0] = "2";
col[1] = "hi";
col[2] = "4,3,2,1";
list.add(col);
for(String[] objs : list){
for(String str : objs){
System.out.print(str + "\t");
}
System.out.println();
}
输出将是:
1 hello 1,2,3,4
2 hi 4,3,2,1