![](/img/trans.png)
[英]Found shared references to a collection: OneToMany empty collections refering to same PersistentBag
[英]Collection of collection's references(may be of ArrayList or any other ) and want to use those references to create collections
我有Collection的引用的Collection(可能是ArrayList或任何其他),我想使用这些引用并创建collections.ie
ArrayList courseTitle; //the collection references
ArrayList<Courses> courses=new ArrayList<Course>();
//an arraylist to store those references
现在我想使用这些引用并使用它们创建集合。例如,如果我当然有一个引用“ Maths”或“ Science”。...那么我想创建名称为“ Maths”或“ MathsList”的集合。很困惑如何实现它。需要帮助!!
创建一个具有不同属性的新类,例如课程,例如标题,作者等,
为所创建的类的特定类型实现ArrayList。
例如。
Class CourseDetails{
public String courseTitle;
public String author;
//getters and setters ....
}
并在实现该功能的类中,如下所示创建一个arraylist。
ArrayList<CourseDetails> arrayList = new ArrayList<CourseDetails>();
希望这在一定程度上有所帮助!
与其使用Collection的Collection,不如考虑使用类进行设计。
根据您的查询和评论,您需要以下结构,
课程对象
public class Course {
String courseTitle;
List<Book> books;
List<Instructor> instructors;
}
课程中包含的书籍课程
public class Book {
String name;
String author;
}
课程中包含的讲师课程
public class Instructor {
String name;
String age;
String experience;
}
现在,您可以像下面这样创建数学或科学等课程
List<Course> maths = new ArrayList<Course>
List<Course> science = new ArrayList<Course>
创建一个将数学和科学作为儿童班的父母班课程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.