How do we create an extension that arrange list in ascending/descending order, get min/max from list

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);
}
How was this guide
  • Helpful
  • Not Helpful
0 voters
8 Likes

I have made this post as wiki now anyone can edit this post
Only edit if I do any mistake

3 Likes

Thank you @SRIKAR_B.S.S for edit

1 Like

Awesome Guide @Faraz_Firoz

1 Like

Thank you @SRIKAR_B.S.S

2 Likes

thanks @Faraz_Firoz , :heavy_heart_exclamation::heavy_heart_exclamation:

2 Likes

Please Make a tutorial on how to set color for a component.
BTW your all guides are nice! :star_struck:

2 Likes

Ok I create this tommorow

2 Likes

I have created your guide it only need approval

2 Likes

It’s not a good practice to return Object types when you can return directly with their original form.

6 Likes

whre jar library

How can create libraries and use it in niotron extension builder block please create any tutorial or example post on it

@deepak661 Create extensions in Niotron IDE, export them, and use them in your app by importing the extension into your account.