Several questions about ArrayList

Category: Eclipse
 
smm01
2013-08-20 05:54:22

Sponsored Links
I am not very clear ArrayList usage

first declared private ArrayList billItems = new ArrayList ();

added as follows: (from the database read data is displayed in the drop-down list, the drop-down list to add the selected information added billItems in)
private void appetizerJComboBoxItemStateChanged (ItemEvent event) {
if ((event . getStateChange () == ItemEvent.SELECTED) &&
(appetizerJComboBox.getSelectedIndex ()! = 0))
{
appetizerJComboBox.setEditable (false) ;

billItems.add ((ArrayList) appetizerJComboBox.getSelectedItem ());

}
This code}
have questions? billItems (ArrayList type) in what form the data stored?

there is a do not know how to query the database to retrieve billItems (ArrayList type) in the corresponding data?


Sponsored Links

luzhiyang080
2013-08-20 06:11:32
do not understand why you converted? (ArrayList) appetizerJComboBox
appetizerJComboBox is control how it will turn into ArrayList?
Proposal to change:
billItems.add (appetizerJComboBox.getSelectedItem ()); / / Here I assume you The item is a String, otherwise converted to String

ArrayList can save a lot of things, you can save the basic data types, you can also save the class of the object. Regardless of how that it is an ordered sequence. See jdk document

pubwin81604693
2013-08-20 06:18:46
1) This code problems?
code problems
with ArrayList.add (X), X is only as Object or Collection
appetizerJComboBox.getSelectedItem () obviously just returns an Object, hence no type conversion.
Direct call billItems.add (appetizerJComboBox.getSelectedItem ()); to
2) billItems (ArrayList type) in what form the data stored?
as defined ArrayList billItems = new ArrayList (); did not join types, the default storage type Object.
3) there is a do not know how to query the database to retrieve billItems (ArrayList type) in the corresponding data?
problem too broad.
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.