gpt4 book ai didi

java - 使用 IntelliJ 调试器,是否可以继续进行集合迭代直到变量返回 null?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:02 25 4
gpt4 key购买 nike

以下代码片段是 Spring MVC Controller 的一部分。使用 commons-collections,它迭代 County 对象列表并将其转换为 String[] 列表以返回给客户端。使用“searchTerm”变量的值来查找数据。我经常遇到的问题是,特定的搜索词会导致转换器抛出异常,因为 County .getState() 方法似乎返回 null。所以我想知道如果使用 IntelliJ 的调试器,我可以告诉它不断迭代直到变量为空。断点使我手动跳过每次迭代,但对于大型集合,这可能需要一段时间。

谢谢。

public List<String[]> cityLookup(@PathVariable String searchTerm) {
List<County> counties = countyService.findAllByPartialCity(searchTerm);

return new ArrayList<String[]>(CollectionUtils.collect(counties, new Transformer() {
@Override
public Object transform(Object o) {
return new String[]{((County) o).getId().getCity(), ((County) o).getState().getStateCode()};
}
}));
}

最佳答案

在断点对话框中应该有一个条件选项。

http://jetbrains.dzone.com/tips/set-conditional-breakpoints-id

关于java - 使用 IntelliJ 调试器,是否可以继续进行集合迭代直到变量返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16359348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com