java—在arraylist中获取对象哈希代码而不是对象值

c9qzyr3d  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(306)

我有一个“student”arraylist,只有很少的对象,我想把student arraylist转换成string arraylist,但是我没有在string arraylist中得到student对象值,而是得到了如下的student对象哈希代码student@6acbcfc0“。我在教室类中有一个tostring()方法。忽略其他类型的错误。感谢您的帮助。提前谢谢。

public class Classroom{

    List<Student> participants=new ArrayList<Student>();

    @Override
    public String toString() {

        String results = "";

        for(Student d : participants) {

            results += d.toString(); 
    }
    return results;
  }

public String getParticipantsEmail(){

        ArrayList<String> str = new ArrayList<String>();

        for (int i = 0; i < participants.size(); i++) {

            str.add(participants.get(i).toString());

            System.out.println(str.get(i));
        }
np8igboo

np8igboo1#

在学生类中添加tostring()方法
然后打个电话

System.out.println(student.get(i).toString());
iszxjhcz

iszxjhcz2#

我看不到 Student.toString() . 有这样的吗? participants.get(i).toString() 电话 Student.toString() ,不是 Classroom.toString() .

相关问题