You can use Reflection
get the fields of the class and loop over the fields array and call setAccessible(true)
to allow access if the field is private and get its value
static class Example {
private boolean part1;
private int part2;
private boolean part3;
public Example(boolean part1, int part2, boolean part3) {
this.part1 = part1;
this.part2 = part2;
this.part3 = part3;
}
}
, main
public static void main(String[] args) {
Example example = new Example(true, 1, false);
Field[] fields = example.getClass().getDeclaredFields();
List<String> list = new ArrayList<>();
for (Field f : fields) {
f.setAccessible(true);
try {
list.add(String.valueOf(f.get(example)));
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
String[] strings = list.toArray(new String[0]);
System.out.println(Arrays.toString(strings));
}
, output
[true, 1, false]
More information: Reflection Oracle doc