【发布时间】:2017-12-08 19:23:39
【问题描述】:
我想使用 jdk 8 lambdas 将 List<Properies> 转换为 Map<String,String> 而不执行 for 循环。该地图应包含作为 SubProperty.name 的键和作为 Properties.value 的值。
public class Properties
{
private SubProperty subProperty;
private String value;
public SubProperty getSubProperty()
{
return subProperty;
}
public void setSubProperty(SubProperty subProperty)
{
this.subProperty = subProperty;
}
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
}
public class SubProperty
{
private String category;
private String name;
public String getCategory()
{
return category;
}
public void setCategory(String category)
{
this.category = category;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
【问题讨论】:
-
我投票决定将此问题作为题外话结束,因为:它看起来像是建议家庭作业的基本流练习,但 "3. Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it."。您问题的当前状态不满足这些要求。使用edit 选项来改进它。
-
感谢您的建议,我在 Eclipse 中做了同样的事情,但不知道为什么它只显示 Object 方法。