JDK8 switch使用字串比if else 效率高,親測大資料量資料下
阿新 • • 發佈:2018-11-09
for (TemplateFormVO templateFormVO:templateFormVOS){ formid=String.valueOf(templateFormVO.getFormId()); formId=templateFormVO.getFormId(); switch(formid){ /* case "1933": formDataVoList.add(new FormDataVo(formId, buildingVo.getBuildingCode(), templateFormVO.getTitle()));break;*/ case "1934": formDataVoList.add(new FormDataVo(formId, buildingVo.getBuildingType(), templateFormVO.getTitle())); break; case "1935": formDataVoList.add(new FormDataVo(formId, buildingVo.getAddressType(), templateFormVO.getTitle()));break; case "1936": formDataVoList.add(new FormDataVo(formId, buildingVo.getBuildingStatus(), templateFormVO.getTitle())); break; case "1937": formDataVoList.add(new FormDataVo(formId, buildingVo.getManager(), templateFormVO.getTitle()));break; case "1938": formDataVoList.add(new FormDataVo(formId, buildingVo.getOrdinaryRoomCount(), templateFormVO.getTitle())); break; case "1939": formDataVoList.add(new FormDataVo(formId, buildingVo.getPublicRoomCount(), templateFormVO.getTitle())); break; /* case "1940": formDataVoList.add(new FormDataVo(formId, buildingVo.getBuildingArea(), templateFormVO.getTitle())); break;*/ case "1941": formDataVoList.add(new FormDataVo(formId,String.valueOf(buildingVo.getFloorCount()) , templateFormVO.getTitle())); break; case "1942": formDataVoList.add(new FormDataVo(formId, String.valueOf(buildingVo.getGroundCount()), templateFormVO.getTitle()));
break;
至於原因參考,下面這個連結是資深級的
https://www.cnblogs.com/idorax/p/6275259.html