StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < psmList.size(); i++) {// List<ProteomicsSampleManageEntity> psmList
stringBuilder.append(psmList.get(i).getFastaId())
.append(psmList.get(i).getStatus())
.append(psmList.get(i).getFasta2blastStatus())
.append(psmList.get(i).getPhylogenyTreeStatus())
.append(psmList.get(i).getCombinedFastasStatus())
.append(psmList.get(i).getFasta2alnStatus())
.append(psmList.get(i).getFunctionAnnotationStatus());
String jobQueueElemStatus = jobQueueElemMap.get(psmList.get(i).getFastaId()) == null ? "NA" : jobQueueElemMap.get(psmList.get(i).getFastaId());
stringBuilder.append(jobQueueElemStatus);
}
高效的写法
String str = "";
for (ProteomicsSampleManageEntity psme : psmList) {
str += psme.getFastaId() + psme.getStatus() + psme.getFasta2blastStatus() + psme.getPhylogenyTreeStatus() + psme.getCombinedFastasStatus() + psme.getFunctionAnnotationStatus()
+ (null != jobQueueElemMap.get(psme.getFastaId()) ? jobQueueElemMap.get(psme.getFastaId()) : "NA");
}
String 中 "+"的本质就是使用StringBuilder实现,以上代码并未提高效率,只是方便阅读而已。