개인지도
Guava 기반 솔루션
Guava는 지정된 키 추출기를 기반으로 목록에서 맵을 생성하기위한 편리한 메소드 Maps.uniqueIndex를 제공합니다. ! return maps.uniqueIndex (선택, 새 함수 () { @보수 공개 문자열 적용 (최종 선택 입력) { return input.getName (); } }); }
private MapnameMap(List choices) { final Map hashMap = new HashMap(); for (final Choice choice : choices) { hashMap.put(choice.getName(), choice); } return hashMap; }
private MapnameMap(List choices) { return Maps.uniqueIndex(choices, new Function () { @Override public String apply(final Choice input) { return input.getName(); } }); }
개인지도
private MapnameMap(List choices) { return Maps.uniqueIndex(choices, new Function () { @Override public String apply(final Choice input) { return input.getName(); } }); }
수집기 Rescue
java 8의 수집기 클래스는 맵핑 목록에 대한 강력한 구현을 제공합니다. Tomap Collector는
이 경우 선택 :: getName and function.identity ()를 각각 키와 값을 검색 할 수 있습니다. = 선택 .Stream (). Collect (Collectors.tomap (선택 :: getName, function.identity ());
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3