class odject in list

class odject in list

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

View Answers

October 19, 2011 at 10:53 AM

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());


October 19, 2011 at 6:10 PM

Thanks for help i find the solution.









Related Tutorials/Questions & Answers:
class odject in list
class odject in list  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
odject value - Java Beginners
odject value  hello friends i have one doubt on my coding.am... with my out put. class test { public static void main(String ard... i did one change in my program class test { public String toString
Advertisements
List control class
List control class  Hi... What Class does all list base controls extend? and implement? please give me the name of these classes.....ADS_TO_REPLACE_1 Tnanks   Ans: All list based control extend the ListBase class
PHP list class methods
Function get_class_methods gives the all methods names of the given class. It takes input as class name and returns the array of the methods name PHP LIst Class Methods Example <?php class myclass{ function aa
class
class  Is a class a subclass of itself
class
is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator methods. Task 2 MedalTally.java is a class to model a medal tally, containing
Class
Class, Object and Methods       Class : Whatever we can see in this world all the things... is termed as a class. All the objects are direct interacted with its class
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.
Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples.  Discuss the Number Class in the java.lang package & list all its subclasses with appropriate examples
Version of com.fommil>class-monkey dependency
List of Version of com.fommil>class-monkey dependency
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,,ADS_TO_REPLACE_1 the super class of an exception is throwable class. and the super class of an throwable class
wrapper class
wrapper class  list wrapper class methods
Version of com.julianpeeters>case-class-generator_2.10 dependency
List of Version of com.julianpeeters>case-class-generator_2.10 dependency
Version of com.julianpeeters>case-class-generator_2.11 dependency
List of Version of com.julianpeeters>case-class-generator_2.11 dependency
Version of com.kreattiewe>case-class-mapper_2.11 dependency
List of Version of com.kreattiewe>case-class-mapper_2.11 dependency
List
List  i do have one list object, i want to compare this list from database table and if match found i want to update the list
List
List  getting values from a form and make a list of them and store them into database
Version of com.larrymite>js-class-loader-parent dependency
List of Version of com.larrymite>js-class-loader-parent dependency
Class
Class       This section explores the concept of a class in reference to object oriented programming techniques. A class defines the properties of  objects and methods used
Java AclNotFoundException Class Hierarchy Diagram
Control List) which has no existence. Hierarchy of this class is shown...In this section we will discuss about the class hierarchy of AclNotFoundException Class in Java. This class extends the java.lang.Exception class
J2ME List Image
with image symbol. In this example we are trying to create list using of List class. The List class define in two type of constructors, that is:ADS_TO_REPLACE_1...[] stringElements, Image[] imageElements)  The List class has following
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
.class and .tld
.class and .tld  how to create .class and .tld file
class loaders
class loaders   Explain static and dynamic class loaders
class file
class file  How to create class file in jsf easily
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
Node class
Node class   hii, What is a node class?   hello,ADS_TO_REPLACE_1 A node class is a class that has added new services or functionality beyond the services inherited from its base class
objective c extending a class with a class
objective c extending a class with a class  I need an example for extending a class with a class in objective c. thanks
objective c extending a class with a class
objective c extending a class with a class  I need an example for extending a class with a class in objective c. thanks
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
printstrim class
printstrim class  discribe PrintStream class
printstrim class
printstrim class  discribe PrintStream class
lock on a class
lock on a class  hello, Can a lock be acquired on a class?   hiii,,ADS_TO_REPLACE_1 Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object
Java class
Java class  What is the purpose of the Runtime class
immutable class
immutable class  How to make a class immutable
Locale class
Locale class  What is the Locale class
singleton class
singleton class  What is singleton class
Abstract class
Abstract class  Can an abstract class be final
Abstract class
Abstract class  what is an Abstract class
wrapper class
wrapper class  wrapper class methods
coolection class
coolection class  how to find maximum and minimum from a list using max & min method of collection class   Here is an example... class i.e max() and min() respectively. import java.util.*; class
robot class
robot class  please send me uses of robot class and some examples using robot class
Nested class
Nested class  What is nested class?  when a class is defined within another class then such a class is called a nested class. Nested... readable and maintainable code. class OuterClass { ... static class
Given a list of methods for a stateful or stateless session bean class, define which of the following operations can be performed from each of those methods: SessionContext interface metho
Given a list of methods for a stateful or stateless session bean class...;Next     Given a list of methods for a stateful or stateless session bean class, define which of the following operations can
class file
class file  how to convert java classfile into java sourcefile
abstract class
abstract class  Can there be an abstract class with no abstract methods
java.sql.DriverManager class
java.sql.DriverManager class  Why isn't the java.sql.DriverManager class being found

Ads