I have a class which has 3 int variables named: day, month and year.
I also have a method called toString() that would take the three fields and return in the format "dd/mm/yyyy" (there is no need to put 0 if the day or month has only 1 number in it).
What is the best way to do this?
public String toString(){
String dateString = this.day + "/" + this.month + "/" + this.year;
return dateString;
}
OR
public String toString(){
String dateString = Integer.toString(this.day) + "/" + Integer.toString(this.month) + "/" + Integer.toString(this.year);
return dateString;
}
String.format("%d/%d/%d", day, month, year)? You can even add leading zero in the format if you need.