简体   繁体   English

集合引用的集合(可以是ArrayList或任何其他集合),并希望使用这些引用来创建集合

[英]Collection of collection's references(may be of ArrayList or any other ) and want to use those references to create collections

I have Collection of collection's references(may be of ArrayList or any other ) and I want to use those references and create collections.ie 我有Collection的引用的Collection(可能是ArrayList或任何其他),我想使用这些引用并创建collections.ie

ArrayList courseTitle;   //the collection references   
ArrayList<Courses> courses=new ArrayList<Course>(); 
//an arraylist to store those references

now i want to use these references and create collections with them.ie like if i have a reference 'Maths' or 'Science' in course....then i want to create collection with name 'Maths' or 'MathsList'.I am confused how to implement it.need help!! 现在我想使用这些引用并使用它们创建集合。例如,如果我当然有一个引用“ Maths”或“ Science”。...那么我想创建名称为“ Maths”或“ MathsList”的集合。很困惑如何实现它。需要帮助!!

Create new class which has the different attributes like courses like title, author etc., 创建一个具有不同属性的新类,例如课程,例如标题,作者等,

Implement an ArrayList for the specific type of class that is created. 为所创建的类的特定类型实现ArrayList。

Eg. 例如。

Class CourseDetails{
      public String courseTitle;
      public String author;
       //getters and setters ....

}

And create an arraylist as below in your class where you are implementing the functionality. 并在实现该功能的类中,如下所示创建一个arraylist。

ArrayList<CourseDetails> arrayList = new ArrayList<CourseDetails>();

Hope this helps to some extent! 希望这在一定程度上有所帮助!

Instead of using Collection of collection's , you should think of designing with classes. 与其使用Collection的Collection,不如考虑使用类进行设计。

As per your query and comment you want the structure as follows, 根据您的查询和评论,您需要以下结构,

Course object 课程对象

public class Course {
    String courseTitle;
    List<Book> books;
    List<Instructor> instructors;
}

Book class included in Course 课程中包含的书籍课程

public class Book {
    String name;
    String author;
}

Instructor class included in Course 课程中包含的讲师课程

public class Instructor {
    String name;
    String age;
    String experience;
}

Now you can create courses like maths or science like below 现在,您可以像下面这样创建数学或科学等课程

List<Course> maths =  new ArrayList<Course>
List<Course> science =  new ArrayList<Course>

创建一个将数学和科学作为儿童班的父母班课程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM