使用system.out.print和java流
我有下面的代码将每个条目映射到print语句,但它显示了错误使用system.out.print和java流,java,java-stream,Java,Java Stream,我有下面的代码将每个条目映射到print语句,但它显示了错误 我的理解有什么问题吗 如何在streams API中使用System.out.println()?如何更正以下代码 public static void main(String[] args) { Properties p = new Properties(); p.setProperty("name", "XYX"); p.setProperty("email", "xyx@mail.com");
我的理解有什么问题吗
如何在streams API中使用
System.out.println()
?如何更正以下代码
public static void main(String[] args) {
Properties p = new Properties();
p.setProperty("name", "XYX");
p.setProperty("email", "xyx@mail.com");
p.setProperty("address", "addr-street-city");
p.entrySet().stream().map(e ->
System.out.println(" " + e.getKey().toString() + " " + e.getValue().toString() + ""));
}
或
或
如果要使用
映射
:
p.entrySet().stream()
.map(e -> " "+e.getKey()+" "+e.getValue())
.forEach(System.out::println);
如果要使用
映射
:
p.entrySet().stream()
.map(e -> " "+e.getKey()+" "+e.getValue())
.forEach(System.out::println);
- .map(…)-将
转换为字符串格式键值
- .forEach(…)-打印字符串
您的输出应该如下所示:
address : addr-street-city
email : xyx@mail.com
name : XYX
- .map(…)-将
转换为字符串格式键值
- .forEach(…)-打印字符串
您的输出应该如下所示:
address : addr-street-city
email : xyx@mail.com
name : XYX
您没有将值映射到打印语句,而是将值映射到其他一些值。为什么scala中的以下内容“val l:List[Int]=List(1,2,3);l.toStream.map(x=>print(x))”会打印1?我没有使用scala的经验,您应该咨询有经验的人。您没有将值映射到打印语句,您可以将值映射到其他一些值。为什么在scala中“val l:List[Int]=List(1,2,3);l.toStream.map(x=>print(x))”会打印1?我没有使用scala的经验,您应该咨询有经验的人。
address : addr-street-city
email : xyx@mail.com
name : XYX