To be beautiful, you need to do either the constructor in the DocType , or a similar static method of the form:
public DocType(ru.server.model.DocType docType){ this.id = docType.getId(); this.docident = docType.getDocident(); this.docname = docType.getDocname(); }
or
public static DocType of(ru.server.model.DocType docType){ //of/from/by, как хотите называйте DocType temp = new DocType(); temp.setId(docType.getId()); temp.setDocident(docType.getDocident()); temp.setDocname(docType.getDocname()); return temp; }
and after that your method will be transformed into:
public List<DocType> mapDocType(List<ru.server.model.DocType> docTypes) { return docTypes.stream() .map(DocType::new) .collect(Collectors.toList()); }
or, respectively
public List<DocType> mapDocType(List<ru.server.model.DocType> docTypes) { return docTypes.stream() .map(DocType::of) .collect(Collectors.toList()); }
tempfromdocType, which is in a loop? If you end up with a new list with new objects, then look at stackoverflow.com/questions/715650/… . There are examples using the Stream API. I also recommend baeldung.com/java-copy-list-to-another . There are quite a few examples. - gooamoko 2:29 pm