Java Field.getName()

Syntax

Field.getName() has the following syntax.

public String getName()

Example

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


import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
//  w  ww. j  a  v  a 2 s  . c o  m
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();
      System.out.println(name);
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable