Search Results

Search found 2 results on 1 pages for 'user569125'.

Page 1/1 | 1 

  • Adding and removing elements efficiently from Collection object

    - by user569125
    Hi, 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. Adding items to the arraylist object String resultItems[] = paging.getMoveLeftArray().split(","); String fields[]={"id","name","name1"}; leftObj=new ArrayList(); for(int i=0;i<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<name.length;j++) { PropertyUtils.setProperty(bean, fields[j], name[j]); } leftObj.add(bean); } Removing items from the arraylist object:availableList contains all the TestVO objects: String []removeArray=paging.getMoveRightArray().split(","); tempList=new CopyOnWriteArrayList(); newTempList=new CopyOnWriteArrayList(); for(int i=0;i<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<removeArray.length;j++){ String resultItem = removeArray[j]; String idandname[] = resultItem.split("@"); for(int k=0;k<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); }

    Read the article

  • Pagination in Java

    - by user569125
    I wrote paging logic: My requirement: total elements to display:100 per page,if i click next it should display next 100 records,if i click previous 100 records. Initial varaible values: showFrom:1, showTo:100 max elements:depends on size of data. pageSize:100. Code: if(p*emphasized text*aging.getAction().equalsIgnoreCase("Next")){ paging.setTotalRec(availableList.size()); showFrom = (showTo + 1); showTo = showFrom + 100- 1; if(showTo >= paging.getTotalRec()) showTo = paging.getTotalRec(); paging.setShowFrom(showFrom); paging.setShowTo(showTo); } else if(paging.getAction().equalsIgnoreCase("Previous")){ showTo = showFrom - 1; showFrom = (showFrom - 100); paging.setShowTo(showTo); paging.setShowFrom(showFrom); paging.setTotalRec(availableList.size()); } Here i can remove and add the elements to the existing data.above code works fine if i add and remove few elements.but if i remove or add 100 elements at a time counts are not displaying properly above code works fine if i add and remove few elements.

    Read the article

1