[英]How to create 2D array of Object from a List?
I would like to convert ArrayList
into 2D array of Objects
. 我想将ArrayList
转换为Objects
2D数组。 List is something like 清单就像
[[AD,ADCB, N], [AFC, Fund, Y], [IO, dfdfdfd, N]]
I would like to convert this List into array of objects and I would like to modify Y, N field into Boolean Values someting like 我想将此列表转换为对象数组,并想将Y,N字段修改为布尔值,例如
Object[] rowdata = {
{AD, ADCB, Boolean.FALSE},
{AFC, Fund, Boolean.TRUE},
{IO, dffdfdf, Boolean.FALSE}}
after that I can stuff into JTable
model and those boolean
values will be visible as JCheckboxes
. 之后,我可以放入JTable
模型中,并且这些boolean
值将显示为JCheckboxes
。
What should be the best way to convert this list into 2D array of objects so that I can pass into JTable
TableModel
? 将列表转换为2D对象数组以便可以传递到JTable
TableModel
的最佳方法应该是什么?
In your example, you show that there are three members of each object that you want to store. 在您的示例中,您表明要存储的每个对象有三个成员。 So, if N is the number of items in your arraylist, you need a multidimensional array of N * 3. ie: 因此,如果N是数组列表中的项数,则需要N * 3的多维数组。即:
Object[][] table = new Object[list.size()][3];
Then you're going to use a for loop, to cycle through each object in the list: 然后,您将使用一个for循环,循环遍历列表中的每个对象:
for(int x = 0; x < list.size(); x++)
{
Object currentObject = list.get(x);
table[x][0] = currentObject.getValue();
// Load the first value.
...
table[x][2] = currentObject.getYorN().equalsIgnoreCase("Y")? true:false;
// Embed a selection statement to decide if to store true or false.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.