jGuru Forums

Iterate about the Vector and operate with his Objects
1 posts in topic
Flat View
TOPIC ACTIONS:

Posted By:   Helen_Mayers
Posted On:   Friday, August 6, 2004 02:09 AM

Hello to everybody, Do sombody ever heard about the problems that can be produced if you Iterate about the Vector, delete unnassesary and put some othe object inside. My Boss has this opinion. My code is following: vector_aktuell -is allready set. public Vector compareAndAktualise(Object[] a_NewData) { Object obj_old; Object obj_new; int index; if (a_NewData == null) { a_NewData = new Object[0]; } for (int i = 0; i < vector_aktuell.size(); i++) { obj_old = vector_aktuell.elementAt(i); index = findElemInArray(a_NewData, obj_old); if (index >= 0) { obj_new = aktualiseElem   More>>

Hello to everybody,

Do sombody ever heard about the problems that can be produced if you Iterate about the Vector, delete unnassesary and put some othe object inside. My Boss has this opinion.
My code is following:

public Vector compareAndAktualise(Object[] a_NewData) {

Object obj_old;

Object obj_new;

int index;

if (a_NewData == null) {

a_NewData = new Object[0];

}

for (int i = 0; i < vector_aktuell.size(); i++) {

obj_old = vector_aktuell.elementAt(i);

index = findElemInArray(a_NewData, obj_old);

if (index >= 0) {

obj_new = aktualiseElement(obj_old, a_NewData[index]);

vector_aktuell.remove(i);

a_NewData[index] = null;

}

else {

deleteElement(obj_old);

vector_aktuell.remove(i);

}

}

for (int i = 0; i < a_NewData.length; i++) {

if (a_NewData[i] != null) {

}

}

return vector_aktuell;

On his opinion i schould use tow helpVectors, but it makes the performance worse, isn't it?

Thanks and sorry for my bad english.

<<Less

Re: Iterate about the Vector and operate with his Objects

Posted By:   Srikanth_B
Posted On:   Tuesday, September 21, 2004 02:32 AM

could you please give the problem instead of presenting the entire program