getting all static variables in a class into array/list
You could use reflection:
Field[] fields = DummyClass.class.getDeclaredFields();
for (Field f : fields) {
if (Modifier.isStatic(f.getModifiers()) && isRightName(f.getName())) {
doWhatever(f);
}
}
If you have a class with constants and want to get the actual values of your java constant you can do following:
List<String> constantValues = Arrays.stream(DummyClass.class.getDeclaredFields())
.filter(field -> Modifier.isStatic(field.getModifiers()))
.map(field -> {
try {
return (String) field.get(DummyClass.class);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
})
.filter(name -> ! name.equals("NOT_NEEDED_CONSTANT") // filter out if needed
.collect(Collectors.toList());