Problem creating object

ynnr85

New member
Hi, everybody
I have a problem writing a service code:

objectInstance : Has a char atribute (character)
It is created before the iteration, when I do this, the atribute character has always the same value for all objects, it is not overwrite in every objectInstance.character = params.string.charAt(j)
It only works when I create the object inside the iteration, but this solution is too slow, because I must to create a lot of objects (more than 1000000).
I need to know if in Grails exist a way to use the same object for every iteration, just modifying it value.

My service code:
Code:
def getCharacter(params){

        def objectInstance= new Object()
        def array = []
		int a = 0
      
                for(int j =0; j<params.string.size();j++){
                                     
                     objectInstance.character = params.string.charAt(j)
                     array[a] = objectInstance   
					 a++					  
                    }
			
        return array
	}


My gsp code

Code:
...
	 <g:each in="${array}" status="i" var="a">
              <td>${i+1}</td>
              <td> ${a.character}</td>			  
	 </g:each>
 ...

Character is always the same

Thank you very much
 
Top