get Class Fields List - Android java.lang.reflect

Android examples for java.lang.reflect:Class

Description

get Class Fields List

Demo Code


//package com.java2s;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static List<String> getFieldsList(Class<?> bean) {
        List<String> list = new ArrayList<String>();
        Field[] fields = bean.getFields();
        if (fields != null) {
            for (int i = 0; i < fields.length; i++) {
                list.add(fields[i].getName());
            }/*from  w ww  . j  a va2  s.co  m*/
        }
        return list;
    }
}

Related Tutorials