如何遍历对象数组列表 [英] How to Iterate through List of Object arrays
本文介绍了如何遍历对象数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Criteria crit = session 所以现在我有一个包含一段代码的程序。 .createCriteria(Product.class);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.max(price));
projList.add(Projections.min(price));
projList.add(Projections.countDistinct(description));
crit.setProjection(projList);
列表结果= crit.list();
我想迭代results.So先谢谢您提供的任何帮助/建议。在这种情况下,您将拥有一个列表,其元素是以下数组:
[maxPrice,minPrice,minPrice,计数]。
....
列表< Object []> results = crit.list();
for(Object [] result:results){
Integer maxPrice =(Integer)result [0];
整数minPrice =(整数)结果[1];
长计数=(长)结果[2];
}
So right now I have a program containing a piece of code that looks like this...
Criteria crit = session.createCriteria(Product.class);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.max("price"));
projList.add(Projections.min("price"));
projList.add(Projections.countDistinct("description"));
crit.setProjection(projList);
List results = crit.list();
I want to iterate results.So thank you in advance for any help/advice that is offered.
解决方案
In this case you will have a list whose elements is an array of the following: [maxPrice,minPrice,count].
....
List<Object[]> results = crit.list();
for (Object[] result : results) {
Integer maxPrice = (Integer)result[0];
Integer minPrice = (Integer)result[1];
Long count = (Long)result[2];
}
这篇关于如何遍历对象数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文