May I know how can I sort a List<Object[]>
and order by more than one element ?
below is my code: I retrieve my result from database using below code
public List<Object[]> readyToPrint() {
Query query = em.createNativeQuery("SELECT
so_order_no,so_bo_suffix,shortname1,ETD......;
List<Object[]> allObject = query.getResultList();
return allObject;
}
As what I know I can only read the result using Object am I right ? So i think i don't have any specific class. Then if the result of element[X] meet certain condition, I want to edit the content of that element, and then only I resorting the result again.
Then i retrieve my result using below code:
`List<Object[]> allList = salesOrderFacade.readyToPrint();
readyToPrintResult = new ArrayList<>();
for (Object[] list : allList) {
if (outgoingFacade.checkReadyToDelivery(list[0].toString(), list[1].toString())) {
readyToPrintResult.add(list);
}
}
I want to sort my
readyToPrintResult` list by element 2 and follow by element 3.
I tried the code below;
Collections.sort(readyToPrintResult, new Comparator<Object[]>() {
@Override
public int compare(Object[] lines1, Object[] lines2) {
return lines1[2].xxxxx;
}
});
but I stuck in the return part. I not able to use "compare" code.
Example: I have a List of result :
-Apple , 11-01-2017 , Y , N
-Bubble ,11-01-2017 , Y ,N
-Cat , 11-01-2017 , Y ,N
-Dora , 11-01-2017 , N ,Y
-Elephant,11-01-2017, N,Y
Then if Elephant meet some condition, I want to change the list of result of elephant to :
Elephant,11-01-2017, Y,N
Then I would like to sorting the whole list and my expected result is as below: -Apple , 11-01-2017 , Y , N
-Bubble ,11-01-2017 , Y ,N
-Cat , 11-01-2017 , Y ,N
-Elephant,11-01-2017, Y,N
-Dora , 11-01-2017 , N ,Y
Anyone can help? Thanks in advance