我想在 C 中打开一个 .txt 文件并读取 .txt 文件中的名称值对以及不同变量中的每个值。txt 文件只有 3 行。
Name1 = Value1
Name2 = Value2
Name3 = Value3
Run Code Online (Sandbox Code Playgroud)
我想提取与名称 1、2 和 3 对应的值并将它们存储在变量中。我该怎么办?
我需要使用对象中 3 个级别的 getter。
response.getServiceError().getErrorCode()
Run Code Online (Sandbox Code Playgroud)
一个或多个对象可能为 NULL。现在,我正在这样做
if (response != null && response.getServiceError() != null && response.getServiceError().getErrorCode() != null && response.getServiceError().getErrorCode().equals("errCode123")) {
//doSomething;
}
Run Code Online (Sandbox Code Playgroud)
有没有更好和/或优雅的方式来构建 if 条件?
我有一个方法,效果很好。这就是它的样子。
private boolean roomWithMoreThanTenFurnitures(Building building) {
if (building != null && building.hasRooms()) {
for (Room room : building.getRooms()) {
if (room.getFurnitures.size() > 10) {
return true;
}
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我想把它切换到 Lambda。uo 是用 shell 进来的,但是我不知道外面如何填写 if(条件) return true 或 return false。
building.getRooms().forEach(room -> {
//??
});
Run Code Online (Sandbox Code Playgroud)