I am trying to get data out of a list,but facing some issue while getting the data.
List<Field> errorFieldList;
Set<String> formValidationResult = new HashSet<String>();
Here the data added to validationResults is like and errorFieldList size is two having Id and type
validationResults.put(errorFieldList, formValidationResult);
public ValidationResponseErrorView(
Map<Object, Set<String>> validationResults, String exceptionMessage) {
if (validationResults.size() > 0) {
for (Map.Entry<Object, Set<String>> entrySet : validationResults
.entrySet()) {
Map<String, Object> fieldResultsMap = new HashMap<String, Object>();
Object objField = entrySet.getKey();
if (objField instanceof List) {
for (int i = 0; i < ((List<Map<String, Object>>) objField)
.size(); i++) {
LOGGER.info("in array list----" + objField);
}
}
}
}
}
I am not sure how to get data out of objField.
Your code is really hard to read and contains a lot of inconsistencies. Especially in your constructor you declare validationResults as
But in your introduction you declare it as
which means your
Objectis aList<Field>. So now you can simply use:to retrieve the values, where
iis your index you iterate over. HOWEVER: your code probably won’t compile, since you try to cast theList<Field>toList<Map<String, Object>>in the 2ndforloop.Simply put: rework the code, A
Maphas getter methods for the key and over aSetyou need to iterate. Check first what data structure you need. Don’t nest too deep.