My class must have an attribute of type string which can have just four values :
value1, value2, value3, or value4 ;
How it can be done in java ?
Use enumerated types, for example
public enum MyStringType {
value1{
public String toString() {
return "this is value1";
}
},
value2{
public String toString() {
return "this is value2";
}
}
/* etc etc */
}