By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

replace the element of an array of objects

P: 20
Can anyone help me??

I have an array of objects for a class. The class has two arraylist variables.

I want to

1) replace one particular object with another object with new arraylist values.

2) replace another particular object with arraylist values set to null

3)in the output, objects in the array should be in an order in which the object having arraylist values set to null (the object in 2 point) should be in the end of the array of objects..
Mar 8 '12 #1
Share this Question
Share on Google+
1 Reply

P: 13,264
To replace an object in an array just assign the index to the new object

Expand|Select|Wrap|Line Numbers
  1. objectArray[index] = theNewObject;
To replace an object in an arraylist just use the ArrayList.set method

Expand|Select|Wrap|Line Numbers
  1. arrayList.set(index, theNewObject);
Mar 8 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.