Adding and removing elements efficiently from Collection object
<p>Below coding is the working sample,but still i am not happy with this code with related to performancewise.Please have a look and let me know if any better approach is there.Thanks in advance.</p>

<p><strong>Adding items to the arraylist object</strong></p>

<pre><code>String resultItems[] = paging.getMoveLeftArray().split(",");
String fields[]={"id","name","name1"};

leftObj=new ArrayList();

for(int i=0;i&lt;resultItems.length;i++){

//below line mea

TestVO bean=new TestVO();

String resultItem = resultItems[i];

String idANDname[] = resultItem.split("@");

String id = idANDname[0];

// name or id should not contain "-"

String name[] = idANDname[1].split("-");

//values and fileds are always having same length

for(int j=0;j&lt;name.length;j++) {

PropertyUtils.setProperty(bean, fields[j], name[j]);

}

leftObj.add(bean);

}
</code></pre>

<p><strong>Removing items from the arraylist object:availableList contains all the TestVO objects:</strong></p>

<pre><code>String []removeArray=paging.getMoveRightArray().split(",");

tempList=new CopyOnWriteArrayList();

newTempList=new CopyOnWriteArrayList();

for(int i=0;i&lt;availableList.size();i++){

boolean flag = false;

TestVO tempObj = (TestVO )availableList.get(i);

int id =(Integer)tempObj.getId();

// System.out.println("id value"+id);

// availableList.get(i).getClass().getField(name);

for(int j=0;j&lt;removeArray.length;j++){

String resultItem = removeArray[j];

String idandname[] = resultItem.split("@");

for(int k=0;k&lt;idandname.length;k++){

String ids[]=idandname[0].split("-");

if(id==Integer.parseInt(ids[0])){

flag = true;

break;

}

}

}

if(flag){

tempList.add(tempObj);

}

else{

newTempList.add(tempObj);

}
</code></pre>
