I have list:
JavaScript
x
var skillsList: MutableList<ComplexModel> = mutableListOf()
ComplexModel contains (Name,Title,StartDate,Summarry)
I want to find better way to create new MutableList from skillsList but the new list have to get only Name and Title from the first.For the moment i`m with this solution but i wonder if there are better way to achieve this.
JavaScript
val newArray: MutableList<SkillModel> = mutableListOf()
for (skill in skillsList) {
newArray.add(SkillModel(name = skill.name, title = skill.title))
}
Advertisement
Answer
JavaScript
var skills: List<SkillModel> = skillsList.map { SkillModel(it.name,it.title) }