In this guide we will learn how we can create an extension that arranges list in ascending/descending order and gets min/max from list
This is my third guide
My first guide How do we create an extension for Niotron?
My second guide Why java do not work if we copy and paste it in Extension developement?
In java we use Collections.sort(YourList);
To arrange list in ascending order but in extension development we use like this
As I told you to create any extension first we need import
so, we need to import collections
and for list we need to import list
Import of collections is import java.util.Collections;
Import of list is import java.util.List;
@SimpleFunction(description = "Arrange list in ascending order")
public Object AscendingOrder(List list) {
return Collections.sort(list);
}
Now descending order
For descending order we arrange in ascending then reverse that list
In java we use Collections.reverse(YourList) to reverse your list
@SimpleFunction(description = "Arrange list on descending order")
public Object DescendingOrder(List list) {
List ascending = Collections.sort(list);
return Collections.reverse(ascending);
Now get max value from list
For getting max value we arrange list in ascending order and then get the first object from list
@SimpleFunction(description = "Get max value from list")
public Object Max(List list) {
List ascending = Collections.sort(list);
return ascending.get(max.size() - 1);
Now get min value from list
For getting min value we arrange list in ascending order and then get the last object from list
@SimpleFunction(description = "Get min value from list")
public Object Min(List list) {
List ascending = Collections.sort(list);
return ascending.get(0);
}
- Helpful
- Not Helpful