Issue
code in the repository is
@Query("select divisionName, count(stundeName)FROM StudentDetails GROUP BY divisionName")
public List<Object> getDivisionCount();
and code in service is
List <Object> countList= studentDetailsRepository.getDivisionCount();
now I want to iterate through countList and categories then into different categories, I tried this
for(int i=0;i< countList.size();i++ )
System.out.println(countList.get(i).getClass().getDeclaredField('count'));
it's not working and giving an error
Solution
You can iterate through your list of object like this and create an object array for each one in your list and then display it :
for (Object object : countList){
Object[] objArray = (Object[]) object;
System.out.println((String)objArray[0]); // divisionName
System.out.println((Integer)objArray[1]); // the count
}
Answered By - Omar Moalla