ArrayList条目大小返回

时间:2014-01-29 11:35:06

标签: java object arraylist size

我在ArrayList.size()返回时收到错误。

我的代码

public class College
{
    Student s = new Student();
    ArrayList <Student> entries;

    public College() {
        entries = new ArrayList<Student>();
    }

    public int getSize() {
        return entires.size();
    }
}

错误

College.java:21: error: cannot find symbol
    return entires.size();
                   ^
symbol:   variable entires
location: class College

这是什么错误?有谁可以帮助我?

提前致谢。

4 个答案:

答案 0 :(得分:0)

public int getSize()
{
    return entries.size(); //you had a typo here
}

答案 1 :(得分:0)

你有一个错字。您使用entries方法getSize时,属性名称为entires

因此,编译器会告诉您它找不到名称为entires的任何内容。

答案 2 :(得分:0)

存在拼写错误。

应该是

public class College
{
Student s = new Student();
ArrayList <Student> entries;
public College()
{
    entries = new ArrayList<Student>();
}
    public int getSize()
{
    return entries.size();
}

答案 3 :(得分:0)

该错误意味着编译器找不到entires.size();

这样做的原因是你的arraylist被称为别的东西; entries

现在当编译器运行时,它无法识别entires.size();作为方法并向您抛出错误。