反转列表<对象>对象>
列表listDataClient;
我的类 DataCLient:
Client client;
List<String> phoneNumber;
我有第二个列表
List<DataPhoneNumber> listPhoneNumber;
我的类 DataPhoneNumber:
String phoneNumber;
List<Client> client;
在我的代码中,我将数据放入第一个列表中,但现在我想在第二个列表中反转我的列表。在第一个列表中,我有一个带有 x NumberPhone 的客户端,现在我想要 x 客户端的 NumberPhone
List listDataClient;
My class DataCLient:
Client client;
List<String> phoneNumber;
i have a second list
List<DataPhoneNumber> listPhoneNumber;
My class DataPhoneNumber:
String phoneNumber;
List<Client> client;
In my code i put data in my first list but now i want to reverse my list in the second. In the first list i have a Client wiht x NumberPhone now i want to have NumberPhone for x Client
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您正在尝试建模多对多关系。
一种方法是创建一个类来显式表示这种关系:
PhoneNumberAssociation
;例如,当他们在关系中没有明显的父母或孩子角色时,我倾向于采用这种方法。它也比在多个对象中嵌入列表并且必须根据是否将电话号码添加到客户端/从客户端中删除(或者相反,如果将客户端添加到电话号码/从电话号码中删除)来链接添加/删除调用更简单)。
It sounds like you're trying to model a many-to-many relationship.
One approach would be to create a class to explicitly represent this relationship:
PhoneNumberAssociation
; e.g.I tend to favour this approach when their is no obvious parent or child role in the relationship. It is also simpler than embedding lists in multiple objects and having to chain calls to add / remove based on whether a phone number is being added to / removed from a client (or conversely if a client is being added to / removed from a phone number).