Get fields in this class

ReturnMethodSummary
FieldgetField(String name)Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object.
Field[]getFields()Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object.

  import java.lang.reflect.Field;

public class Main {
  public static void main(String args[]) {

    System.out.println("Fields:");
    Field fields[] = new String().getClass().getFields();
    for (int i = 0; i < fields.length; i++) {
      System.out.println(" " + fields[i]);
    }
  }
}

The output:


Fields:
 public static final java.util.Comparator java.lang.String.CASE_INSENSITIVE_ORDER
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.