
I have three class. In first class i have get and set methods, in second class i have a list of objects of first class then after main class i want to read the objects values but it will shows only the memory allocation by the object not given the class object values. my classes is like that--->
1st class:-
public class preAuthor {
private long id;
private String name;
public preAuthor(String name){
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String list) {
this.name = list;
}
}
2nd class-->
import java.util.List;
public class Author{
private List<preAuthor> preAuth;
public List<preAuthor> getAuthor() {
return preAuth;
}
public void setAuthor(List<preAuthor> preAuth) {
this.preAuth = preAuth;
}
}
Main class:-
public class mainclass{
public static void main(String args[]) {
preAuthor auth=new preAuthor(null);
auth.setName("sud");
auth.setName("shekhar");
ArrayList<preAuthor> lst=new ArrayList<preAuthor>();
lst.add(auth);
Author au=new Author();
au.setAuthor(lst);
Iterator<preAuthor> itr=au.getAuthor().iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
}
}
please help me to get the values. Thanks

Hi it seems that you are printing the object to print the object value here you will have to override the toString() method of object class here or you will have to call the setter and getter method
like
System.out.println(itr.next().getName());

Thanks for help i find the solution.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.