Array Functions

Convert ArrayList to Array

importPackage(java.util);
importClass(java.util.ArrayList);

var varArrayList = new ArrayList();
varArrayList.add ( "Item 1" );
varArrayList.add ( "Item 2" );
varArrayList.add ( "Item 1" );

print ();
print ( varArrayList );
print ( arrayListConvert (varArrayList) );

function arrayListConvert (arrayList)
{
  var varArray = new Array();
  for ( var ee = 0; ee < arrayList.size(); ee++ )
  {
    varArray.push ( arrayList[ee] )
  }
  return varArray;
}

Given the Array List of [Item 1, Item 2, Item 1], the function returns the Array Item 1,Item 2,Item 1

Remove duplicates

varArrayList = new ArrayList ( new HashSet ( varArrayList ) );
varArrayList = arrayListConvert( varArrayList );
varArrayList.sort()
print ( varArrayList )

Given the Array List of [Item 1, Item 2, Item 1], the function returns an Array which can then be sorted to give Item 1,Item 2