Java Reflection - Java Field.getName()


Field.getName() has the following syntax.

public String getName()


In the following code shows how to use Field.getName() method.

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
/*from  w ww. j  a  v a  2 s.  com*/
public class Main{
  public static void main(String[] args) {
    Field[] fields = java.lang.Integer.class.getDeclaredFields();

    for (int i = 0; i < fields.length; i++) {
      Field f = fields[i];
      String name = f.getName();

The code above generates the following result.