Showing results for 
Search instead for 
Did you mean: 

how to store repeated elements in an array

Occasional Contributor

how to store repeated elements in an array

I have 2 responses , one SOAP and one REST. I need to compare the two values and check if they match . I created an an array to store the SOAP taxlots but when I try to log it, it gives an error


so SOAP response is something like this .  


Security 1








REST response is 


Security 1Taxlot

Security 1Taxlot

Security2 Taxlot

Security3 Taxlot



I have been able to read the taxlots for each security in SOAP. I want to store them in a matrix

something like taxlot[1], taxlot[2]...

The number of taxlots are dependent on another field called row count. So I want to use a for loop and store the values .


I tried something like below

secIndex is for security count

taxlotids is the number of taxlot for each security

j is to store the taxlots in an array




def j=0 

for (def secIndex=1;secIndex<val;secIndex++)
def securities=holder.getNodeValues( "//gl:SampleResponse/SecurityList/SecurityInformation[$secIndex]/SecurityNumber[1]") securities.toString()  // logs the security number


def taxlotids =holder.getNodeValues( "//gl:SampleResponse/SecurityList/SecurityInformation[$secIndex]/TaxLotList[1]/TaxLotInformation").length taxlotids // logs the number of taxlots for each security 


int taxlotidsi=taxlotids+1

def matrix= []


for (def ti=1;ti<taxlotidsi;ti++)


def termval= holder.getNodeValues( "//gl:SampleResponse/SecurityList/SecurityInformation[$secIndex]/TaxLotList[1]/TaxLotInformation[$ti]/GainLossForTaxLot[1]/Term[1]" )   // This gets the Taxlotfield



matrix[j]=termval  //Creating an array to store these taxlots. Not sure if its the right way matrix[j].toString() 

j++  //incrementing the array counter j
} matrix[2]   ------ I want to log the value of second taxlot but this gives an error

Community Hero

Re: how to store repeated elements in an array

Some would be able help you or give pointers if you can show the data.

New Here?
Join us and watch the welcome video:
Top Kudoed Authors