package cp;
import java.util.ArrayList;
import java.util.Iterator;
public class Emmo {
public static void main(String[] args){
HelloWorld he=new HelloWorld("https:www.educoder.net");
HelloWorld h=new HelloWorld(20.432);
ArrayList a=he.getList();
a.add(he);
a.add(h);
//Iterator<HelloWorld> it1=a.iterator();
//System.out.println(it1.next());
System.out.println(a.get(0));
}
}
package cp;
import java.util.ArrayList;
public class HelloWorld {
//public ArrayList a;
String str;
double du;
@SuppressWarnings("unchecked")
public HelloWorld() {}
public HelloWorld(double du) {
this.du=du;
}
public HelloWorld(String str) {
this.str=str;
}
public ArrayList getList() {
ArrayList<Object> a=new ArrayList<>();
return a;
}
}
你是用IDEA的吧,在实体类中,重写toString方法,就可以输出内容了,写toString的时候,就会给你来个代码提示
Alt + Inset 可以快速生成toString方法,get/set方法,构造方法都可以用这个快捷键
你这个代码粘的是一塌糊涂。重写toString方法就不会打印地址了