2014-03-02 45 views
-2

我很熟悉java,但是我不熟悉List的Class。我似乎无法找到能够帮助我学习的精确教程。如果有任何教程,请参考我或其他亲切告诉我如何使用List<Class>。例如,列表中的<Class> in java

public class Students { 
    int studentId; 
    String studentName; 
    int studentAge; 
} 

如何使用

List<Students> 

Editted

就像在C结构++,我想这个学生是一个结构数组存储多个学生的数据。正如在Java中没有结构,所以我使用班学生。如果使用List不适合此目的,请亲切指导我。 谢谢!

+0

到底什么做的班级名单有你发布的代码呢?你想用什么类来实现? – user2357112

+1

你不明白你在问什么/不明白。如果它是''的一部分,你应该谷歌泛型。 http://docs.oracle.com/javase/tutorial/java/generics/ – Pshemo

+2

'List myList = new ArrayList ();'然后使用Google或s.th.看看你可以用'list'做什么。 – pzaenger

回答

2

你的命名约定是关闭的,它应该是班级学生而不是学生。并且不要使变量名大写。无论如何,List是一个通用的容器接口,您可以实例化List的具体实现并向其添加学生。

List<Students> theStudents = new ArrayList<Students>(); 

Students aStudent = new Students(); 
aStudent.StudentId = 333; 
aStudent.StudentName = "Help"; 

theStudents.add(aStudent); 
+0

这就是我想问的。你真的是一个帮助:)谢谢! –

1
ArrayList<Students> students = new ArrayList<Students>();