Q:

check whether Field[] contains a field with name XXX

I got an array of Field of a class:
Class<?> clazz = Class.forName(FULL_CLASS_NAME);
Field[] fields = clazz.getFields();

I want to check whether the above fileds array contain a field named "sumUp". I am looking for a way which doesn't iterate through each element of fields. I tried:
String[] fieldNames = Arrays.copyOf(fields, fields.length, String.class);
boolean hasField = Arrays.asList(fieldNames).contains("sumUp")); 

But compiler complains :
The method copyOf(U[], int, Class<? extends T[]>) in the type Arrays is not applicable for the arguments (Field[], int, Class<String>)

I am wondering is it possible to fix the above error? if not, what could be the alternative way ?

A:

You can simply get a field by name by Class.getField(String name):
Class<?> clazz = Class.forName(FULL_CLASS_NAME);
try {
    Field f = clazz.getField("sumUp");
    System.out.println("sumUp field exists");
} catch (NoSuchFieldException e){
    System.out.println("sumUp field does not exist");
}

getField() searches for a public member field. If you also need to find protected and private fields too, you can use Class.getDeclaredField(String name).

