which is best, the Vector or Array?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Antonio_Baez
Posted On:   Tuesday, April 16, 2002 09:06 AM

Hi ! I'm Antonio in my application is using Array and Vector, for save Business Object how ( Structure Class of Data). In Array is: JComboBox strClvClienteEspecial = new JComboBox(); String tempStringClave Structure1[] est1 = new Structure1[3]; est1= Structure1[1].setData(45); est1= Structure1[2].setData(28); est1= Structure1[3].setData(17); for(int i=0; < est1.length; i++){ tempStringClave[i] = ""+est1[i].getData(); strClvClienteEspecial.addItems(tempStringClave); } and Vector is: JComboBox strClvClienteEspecial = new JComboBox();    More>>

Hi ! I'm Antonio



in my application is using Array and Vector, for save Business Object

how ( Structure Class of Data).



In Array is:


JComboBox strClvClienteEspecial = new JComboBox();

String tempStringClave

Structure1[] est1 = new Structure1[3];

est1= Structure1[1].setData(45);

est1= Structure1[2].setData(28);

est1= Structure1[3].setData(17);


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

tempStringClave[i] = ""+est1[i].getData();

strClvClienteEspecial.addItems(tempStringClave);

}



and Vector is:


JComboBox strClvClienteEspecial = new JComboBox();

String tempStringClave

Vector vec1 = new Vector();

vec1.addElement(Structure1.setData(45));

vec1.addElement(Structure1.setData(28));

vec1.addElement(Structure1.setData(17));


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

Strucuture1 = (Structure1)vec1.elementAt(i);

tempStringClave= ""+est1.getData();

strClvClienteEspecial.addItems(tempStringClave);

}



this Structure (Object) is call across the session in EJB.

Question: which is best, the Vector or Array? or which is more recomment for applicacions with much vol?

   <<Less

Re: which is best, the Vector or Array?

Posted By:   Mike_Friedrich  
Posted On:   Monday, April 22, 2002 03:01 AM

Hi, this depends on your needs.
The simple array is not thread-save. But it should be the fastest (if you have fixed small lengths). Generaly you should try to avoid unnecessarily copies of arrays.
You can try this too (if this match your needs):

strClvClienteEspecial.addItem(new Structure1(45));
strClvClienteEspecial.addItem(new Structure1(28));
strClvClienteEspecial.addItem(new Structure1(17));

You only need to add a constructor and toString() method.


If you need the Collection interface, you can use:

class ArrayList (not thread-save / not synchronized)

class Vector (thread-save / synchronized)

or any other of the Collection classes.


And i think you have a bug in your code,

here you destroy the reference to the array:


est1= Structure1[1].setData(45);
est1= Structure1[2].setData(28);
est1= Structure1[3].setData(17);


And you get a ArrayOutOfBoundsException.

Something like:


est1[0].setData(45);
est1[1].setData(28);
est1[2].setData(17);


is better.

Re: which is best, the Vector or Array?

Posted By:   Simon_Ablett  
Posted On:   Wednesday, April 17, 2002 08:33 AM

Antonio,

Please only post your question to a single forum. Cross postings just serve to irritate people.

Regards.
About | Sitemap | Contact