显示其属性后检索Java对象

时间:2017-10-14 10:07:23

标签: java oop object

ArrayList<ShiftModel> ShiftList = db.getAllShifts();     

for(int i = 0; i < ShiftList.size(); i = i + 1   )
{   
    //Displays a nicely formatted String in a combobox 
    comboBox.addItem(ShiftList.get(i).getComboBoxDisplay()); 
}

//returns a String from the combobox I just populated
table.getValueAt(3, 1) 

我想要做的是使用

table.getValueAt(3, 1) 

它返回ShiftModel对象而不是我用来显示它的格式化字符串。

有什么想法吗?非常感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用get本身的ArrayList方法来获取所需的对象,例如:

ShiftModel modelObject = ShiftList.get(3);

这将返回index 3处的值。请注意,您需要确保该列表包含至少index + 1个元素,然后才能重新获得index个帖子中的值。否则你会得到IndexOutOfBoundsException

Here's get方法的jacadoc。

相关问题