Conventionally, you use the type that best fits your scenario.
-
If you need to do math associated with a number, use a datatype capable of that, like
int
,double
,long
,float
, etc. -
If you don’t need to perform math on it, or you’re using it as a label, then a
String
is acceptable.
(In all actuality, if you really wanted to do something with the date, such as subtract two years together, ideally you’d use an appropriate object for that, as well.)
From what you describe, the years are only really meant as a column header, and nothing more is required of them, so a String
is the only appropriate type to use.
0
solved When do you use a String over int [closed]