Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在ArrayList中获取对象哈希代码而不是对象值_Java_Arraylist_Hashcode - Fatal编程技术网

Java 在ArrayList中获取对象哈希代码而不是对象值

Java 在ArrayList中获取对象哈希代码而不是对象值,java,arraylist,hashcode,Java,Arraylist,Hashcode,我有一个包含很少对象的“学生”ArrayList,我想将我的学生ArrayList转换为字符串ArrayList,但我没有在字符串ArrayList中获取学生对象值,而是获取学生对象哈希代码,如Student@6acbcfc0“。我在教室类中有一个toString()方法。忽略其他类型的错误。感谢您的任何帮助。提前谢谢 public class Classroom{ List<Student> participants=new ArrayList<Student>

我有一个包含很少对象的“学生”ArrayList,我想将我的学生ArrayList转换为字符串ArrayList,但我没有在字符串ArrayList中获取学生对象值,而是获取学生对象哈希代码,如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));
        }
公共课堂{
列表参与者=新建ArrayList();
@凌驾
公共字符串toString(){
字符串结果=”;
学生(d:参与者){
结果+=d.toString();
}
返回结果;
}
公共字符串getParticipantsEmail(){
ArrayList str=新的ArrayList();
对于(int i=0;i
我没有看到
Student.toString()的实现。
你有这样的吗

参与者.get(i).toString()
调用
学生.toString()
,而不是
教室.toString()

然后打电话

System.out.println(student.get(i).toString());
Student
类中定义
toString()
方法。