{"id":59,"date":"2009-10-05T16:14:27","date_gmt":"2009-10-05T23:14:27","guid":{"rendered":"http:\/\/shivdev.com\/blog\/2009\/10\/05\/iterate-over-static-fields-and-values-from-a-java-class\/"},"modified":"2011-05-06T07:30:18","modified_gmt":"2011-05-06T07:30:18","slug":"iterate-over-static-fields-and-values-from-a-java-class","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2009\/10\/05\/iterate-over-static-fields-and-values-from-a-java-class\/","title":{"rendered":"Iterate over Static Fields and Values from a Java Class"},"content":{"rendered":"<p>Here&#8217;s a method that shows how to get all the static fields in a Java class and return them.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\tpublic static List printFields(Class c) throws ClassNotFoundException, IllegalAccessException {\r\n    \t\tList fields = new ArrayList();\r\n        java.lang.reflect.Field[] f = c.getDeclaredFields();\r\n        for (java.lang.reflect.Field field : f) {\r\n            int modifier = field.getModifiers();\r\n            if (java.lang.reflect.Modifier.isStatic(modifier)){\r\n          \t\tString val = (String) field.get( null );\r\n          \t\tSystem.out.print(field.getName() +  &quot;: &quot; + val.toString() + &quot;, &quot;);\r\n          \t\tfields.add(val);\r\n            }\r\n        }\r\n        return fields;\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a method that shows how to get all the static fields in a Java class and return them.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/59"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":1,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":191,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/59\/revisions\/191"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}