I am looking for a clean and elegant way to transform an object variables into an array based on the variable values.
Example:
public class Subject {
public Subject(boolean music, boolean food, boolean sport, boolean business, boolean art) {
this.music = music;
this.food = food;
this.sport = sport;
this.business = business;
this.art = art;
}
private final Long id;
private final boolean music;
private final boolean food;
private final boolean sport;
private final boolean business;
private final boolean art;
}
Based on the values of each field, I want to add the field name as a string into an array.
Example:
new Subject(true, true, true, false, false)
Expected result:
["music", "food", "sport"]