0
How to set a primitive data type to only collect a set of values
So in java the boolean primitive data type only accepts true or false. And I want to add a gender attribute to a class. Now I want this attribute to only take male, female or other. And I suppose it's a string I will make use of so is there any way that the String will be set to only accept these values.
1 Respuesta
0
You could use an Enum:
https://code.sololearn.com/cJ3rx4V47SkZ/?ref=app