mardi 12 mars 2019

Java - Parse List

I'm trying to turn a List into simple strings, but I'm not sure how to parse them out of the array into a single String variable.

I'm currently using a method that goes through a class that uses a getDeclaredFields() method and outputs them into an array.

public static List<Field> getInheritedPrivateFields(Class<?> type) {
    List<Field> result = new ArrayList<Field>();

    Class<?> i = type;
    while (i != null && i != Object.class) {
        Collections.addAll(result, i.getDeclaredFields());
        i = i.getSuperclass();
    }

    for(Field temp : result) {
        System.out.println(temp);
    }

    return result;
}

The result I get when I output it is

[private int com.gen.e.ric.report.domain.TestCount.count,
 private java.lang.String com.gen.e.ric.report.domain.Test.facility, 
 private java.lang.String com.gen.e.ric.report.domain.Test.technology,
 private java.lang.String com.gen.e.ric.report.domain.Test.component, 
 private java.util.List com.gen.e.ric.report.domain.Test.etestStats, 
 private java.util.Date com.gen.e.ric.report.domain.Test.startDate, 
 private java.util.Date com.gen.e.ric.report.domain.Test.endDate]

What I want to get is just a long string with

int, String, String, List, Date, Date

Any help to give? Using Reflection btw. Thanks.





Aucun commentaire:

Enregistrer un commentaire