Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ArrayList Question

Status
Not open for further replies.

k4ghg

Technical User
Dec 25, 2001
191
US
I was wondering if someone might help me get a grasp on arrayLists. I've read the books but an still having some problems.

I created a GUI to accept varing records. There are buttons to travers the records and each time I select a button I'm updating the arrayLists. ArrayList.add(Number, object); When I do forward the Number is incremented and when I go back its reduced.

By using the "Number" are are substituing a record or adding a new record and sliding the old one up? The program seems to bomb when I go back and forth between records.

Thanks
 
When you specify an index for the add method, you are in fact inserting the object at that position in the list. The subsequent entries will all be indexed one greater.

This is mentioned in the JDK API Docs.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
ArrayList.add() just adds a record to the list - when you access records, you use the get(int record) method.

Perhaps you could show a quick example to highlight your problem ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thanks...I was suprised that it inserts the value and not replace. If anyone is interested I created two routines. If the item is new its added else I set it in place:

for (int n = 0; n > 10; n++){
if (aID.size ==0){
aID.add(n, ID[n]);
}
else(
aID.set(n, ID[n]);
}
}

Thanks again...Ronnie
 
Maybe you should take a look at HashMap, it stores key-value pairs that you could use to store your buttons.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top