|
I have been reading in different publications by well known authors about how we don't need to be as concerned about instantiating a few extra objects here and there because the processing in JDK1.5 is so much better than that of JDK1.3 (note that these comments have come in from the J2EE crowd). So I have an example I would like comments on below. In one I create my objects outside of the while loop and in the latter one I create the variables within my while loop. Note that I don't need to have access to the variables outside my while loop, but if I declare them outside the while loop I need to initialize them with each loop iteration. My question would be, do I save anything (meaning memory, CPU cycles, etc) by declaring my variables outside my while loop? Integer total1 = new Integer(0); Integer total2 = new Integer(0); Integer total3 = new Integer(0); Integer total4 = new Integer(0); Integer total5 = new Integer(0); Iterator iter = myList.iterator(); while (iter.hasNext()) { total1 = new Integer(0); total2 = new Integer(0); total3 = new Integer(0); total4 = new Integer(0); total5 = new Integer(0); total1 = methodTotal1(); total1 = methodTotal1(); total1 = methodTotal1(); total1 = methodTotal1(); total1 = methodTotal1(); // write totals to PDF } Iterator iter = myList.iterator(); while (iter.hasNext()) { Integer total1 = new Integer(0); Integer total2 = new Integer(0); Integer total3 = new Integer(0); Integer total4 = new Integer(0); Integer total5 = new Integer(0); total1 = methodTotal1(); total1 = methodTotal1(); total1 = methodTotal1(); total1 = methodTotal1(); total1 = methodTotal1(); // write totals to PDF }
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.