[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: programing styles
I seem to recall, that for pure efficiency, the following would be "best":
private void myproc(Vector vect){
for( int i=vect.size(); i >= 0; i-- ){
MyObject obj = (MyObject)vect.elementAt(i);
int y = (MyObject)vect.elementAt(i).getY();
}
}
By iterating over the list backwards you avoid having to recalculate the size of the list on every
iteration.
WM
--- "Gudavalli, Manidhar" <manidhar.gudavalli@eds.com> wrote:
>
>
>
> HI
>
> Which style of coding is best ?
>
> [1]
> private void myproc(Vector vect){
> for (i=1; i < vect.size() ; i++){
>
> MyObject obj = (MyObject) vect.elementAt(i);
> int y = obj.getY();
> }
> }
>
> or
> [2]
> private void myproc(Vector vect){
> MyObject obj = null;
> int y= 0;
>
> for (i=1; i < vect.size() ; i++){
>
> obj = (MyObject) vect.elementAt(i);
> y = obj.getY();
> }
> }
>
__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/