Map:
Map<String,String> map=cargolist.stream().collect(Collectors.toMap(CodeCargo::getCargoCode,CodeCargo::getCargoName));
Map<String, CodeCargo> map=cargolist.stream().collect(Collectors.toMap(CodeCargo::getCargoCode, Function.identity(), (oldValue, newValue) -> oldValue);
Map<String, List<CodeCargo>> map = cargolist.stream().collect(Collectors.groupingBy(CodeCargo::getCargoCode));
LinkedHashMap:
Map<String, CodeCargo> map= cargolist.stream().collect(Collectors.toMap(CodeCargo::getCargoCode, Function.identity(), (oldValue, newValue) -> oldValue, LinkedHashMap::new));
Map<String,List<CodeCargo>> map= cargolist.stream().collect(Collectors.groupingBy(CodeCargo::getCargoCode, LinkedHashMap::new,Collectors.toList()));
List:
List<String> list=cargolist.stream().map(item->item.getCargoId()).collect(Collectors.toList());