我正在使用JSoup来解析网页。
这是我的代码:
List<Element> nodes = inodes.stream()
.filter(n -> n.child(0).text().contains("hello"))
.map(n -> n.data())
.collect(Collectors.toList());
当我运行它时,我收到此错误:
equality constraints: Element
lower bounds: String
where T is a type-variable:
T extends Object declared in method <T>toList()
我该如何解决这个问题?
答案 0 :(得分:1)
Element.data
返回类型为String
,因此collect
返回类型应为List<String>
,如:
List<String> nodes = inodes.stream()
.filter(n -> n.child(0).text().contains("hello"))
.map(n -> n.data())
.collect(Collectors.toList());