Appending a string in a loop in effective way

前端 未结 5 2211
孤城傲影
孤城傲影 2020-12-05 21:15

for long time , I always append a string in the following way.

for example if i want to get all the employee names separated by some symbol , in the below example i

5条回答
  •  广开言路
    2020-12-05 21:50

    For your final pipe issue, simply leave the last append outside of the loop

    int size = EmployeeList.length()
    for(int i = 0; i < size - 1; i++)
    {
         final+=EmployeeList.getEmployee(i).Name+"|";
    }
    final+=EmployeeList.getEmployee(size-1).Name;
    

提交回复
热议问题