How to Iterate through List of Object arrays

前端 未结 3 1560
[愿得一人]
[愿得一人] 2020-12-16 18:38

So right now I have a program containing a piece of code that looks like this...

Criteria crit = session.createCriteria(Product.class);
ProjectionList projLi         


        
相关标签:
3条回答
  • 2020-12-16 19:20

    You can probably do something like this:

    for (Object result : results) {
        // process each result
    }
    
    0 讨论(0)
  • 2020-12-16 19:32

    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];
    }
    
    0 讨论(0)
  • 2020-12-16 19:37

    You could use Generic in List and for each but for current code you could do following to iterate

    for(int i = 0 ; i < results.size() ; i++){
     Foo foo = (Foo) results.get(i);
    
    }
    

    Or better to go for readable for-each loop

    for(Foo foo: listOfFoos){
      // access foo here
    }
    
    0 讨论(0)
提交回复
热议问题