Java String best practices -


i have 4 string parameter's in java (from request object)

string dd = req.getparameter(dd); string mm = req.getparameter(mm); string yyyy = req.getparameter(yyyy); 

after validating dd,mm,yyyy building date object in 4th string variable buildingstring date = dd+"/"+mm+"/"+yyyy; again in places need replace date format following,

date = yyyy+mm+dd; date =mm+"/"+dd+"/"+yyyy;  // storing in db need format 

how memory consume since 4 objects need pass till persist in table? costlier memory call? there best practice? @ last howmany string objects in stringpool?

my suggestion should not worry micro improvement other suggested. may create wrapper object e.g. mydate , construct date object once. after can use different formatter format date.

package com.dd;  import java.text.simpledateformat; import java.util.date;  import org.joda.time.localdate;  public class mydate {      private date date;      public mydate(request req) {         int day = req.getparameter("dd");         int month = req.getparameter("mm");         int year = req.getparameter("yyyy");         date = new localdate(year, month, day).todate();     }      public string format(string givenformat) {         simpledateformat sdf = new simpledateformat(givenformat);         return sdf.format(date);     }  } 

note - need confirm , validate values you're getting request , if in same notation expected localdate


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -