【发布时间】:2019-09-18 06:43:12
【问题描述】:
我的代码:
public class Country {
private final Integer countryId; // PK, primary key
private final String name;
public Country(Integer countryId, String name) {
this.countryId = countryId;
this.name = name;
}
// omitting getters
}
public class State {
private final Integer stateId; // PK
private final Integer countryId; // FK, foreign key
private final String name;
public State(Integer stateId, Integer countryId, String name) {
this.stateId = stateId;
this.countryId = countryId;
this.name = name;
}
// omitting getters
}
public class City {
private final Integer cityId; // PK
private final Integer stateId; // FK
private final String name;
public Integer getCityId() {
return cityId;
}
public Integer getStateId() {
return stateId;
}
public String getName() {
return name;
}
public City(Integer cityId, Integer stateId, String name) {
this.cityId = cityId;
this.stateId = stateId;
this.name = name;
}
// omitting getters
}
public static void main(String[] args){
Set<Country> countries = Collections.singleton(new Country(1, "India"));
Set<State> states = Collections.singleton(new State(1, 1, "Maharastra"));
Set<City> cities = Collections.singleton(new City(500, 30, "sangai"));
}
使用 Lambda 表达式 java,需要像 CountryName、StateName、CityName 这样的输出在 countryId、stateID、cityID 的键上进行内连接。
【问题讨论】:
-
不清楚你在找什么?
-
感谢您的检查。我有三个 List
、List 、List 。使用 lambda express,我如何使用加入 ListCity 和 ListState 的 stateID 并加入 ListState 和 List Country 的 countryID 来加入所有三个列表。最后获取 Country Name、State Name、City Name 的值。 -
不要将此类信息放入 cmets。始终更新您的问题。您真的希望阅读您的问题的人了解它的内容。所以把这样的上下文放在问题的开头。
-
那么,你的问题是什么?
-
您自己尝试了什么,什么有效,什么无效。如果它是来自数据库的数据,你会谈论连接,你会更好地在数据库中而不是在 Java 中进行操作