I was currently working to build my next extension ArrayFunctions.
While making block of removing an item from the list, first I take Yailist list from the user then I converted it into String array then I converted that String array to Array list to perform remove. It is finely compiling with no problem but it is not performing any task in-app and giving an error:
Here is my code:
@SimpleFunction(description=“Remove element from index.It pass the list.”)
//At first i take a input of list and position from user
public YailList RemoveElementFromPosition(YailList list,int position){
//Then i converted it into the String array
String arraylist=list.toStringArray();
//Then i converted this String array to Array list to perform the remove function
List listcopy=Arrays.asList(arraylist);
//Then i remove the element in position -1 whcih is index
listcopy.remove(position-1);
//Then i again converted the array list to array so that i can change it into Yailist
Object arrayout=listcopy.toArray();
//At last i returned the list by converting the array into the Yailist.
return YailList.makeList(arrayout);
Array and ArrayList are different.
This should work fine:
List list = new ArrayList<>();
String[] sArray = yailList.toStringArray();
for (String s:sArray){
list.add(s);
}
list.remove(index - 1);//now you can add and remove items