class Person
{
private String name;
private String profession;
}
profession has values:
- engineer
- Doctor<
My suggestion -
1. Create a new class Profession
-
class Profession{
public Profession(Integer id, String prefessionName){
this.id=id;
this.prefessionName=prefessionName;
}
Integer id;
String professionName;
}
2. Now give Id to each Profession
object/instance maintaining the order. For example -
Profession engineer = new Profession(1, "Engineer"); //since Engineer is in first place
Profession doctor = new Profession(2, "Doctor"); //since Doctor is in second place
Profession teacher = new Profession(3, "Teacher");
Profession student = new Profession(4, "Student");
3. Now sort the Profession
for id
using compareable
interface.